V
V
vladimirkostenko962015-02-02 22:19:02
JSON
vladimirkostenko96, 2015-02-02 22:19:02

How to parse an unusual JSON file in C#?

C# language, JSON format file:
[
[
[1,"Aple",1,"Aple",,1,"s",19],
[2,"Orange",2,"Orange",,0,"bb ",8],
[25,"Raspberry",25,"Raspberry",,1,"-1",1]
]
]
Somehow I parsed json using NewtonSoft - it worked. But I met this file - I don’t understand how to parse it. Knowledge is not enough. Help

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
Evsign, 2015-02-02
@Evsign

It's not json.
When there is valid json , go to json2csharp.com , generate classes.
Then with the help of NewtonSoft
Well, further along the fields in the json object

V
Viktor Vsk, 2015-02-03
@viktorvsk

Unfortunately, this is invalid JSON.
If you look at the spec: www.json.org on the right side of the used tokens column, you can see that an empty value should be passed as null.
You have the sequence ,,
The given source is apparently a little smart himself and makes some assumptions when parsing.
Before parsing, you can try to replace such a regular expression:
. For your example, it will do, but you must remember that this is JSON:
Gathering, the idea did not come up how to highlight non-linear elements with a regular expression. This is probably not so simple, given that any element will be between two quotes very often.
As a first workaround for this situation, you can first separate each array by commas and remove or assign null to empty elements ... But this is not easy and will have its limitations.
This is an invalid data format. It just won't be here.

V
vladimirkostenko96, 2015-02-02
@vladimirkostenko96

online viewer ( jsonviewer.stack.hu/) recognized - displayed the structure. I don't even know what to add.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question