Good day. I need rozparsse a number of such here "objects"
Validen

{ "type": "company", "company": "R20", "position": "Поставщик шин и дисков", "address": "Украина, Днепропетровск, Днепропетровская область, ул.Артема а", "emailArray": [ "info@r25.com.ua" ], "phoneArray": [ "380669811060", "380671911865" ], "urlArray": [], "tags": "шины,диски,поставщик", "comment": null, "source": "tyetraer.ua" } 

The problem is that the validator says that one is so valid, and if there are 2 or more of them in the file (even if they are the same), the file says that the file is no longer valid. Please tell me what is the problem here?

Nevaliden

 { "type": "company", "company": "R20", "position": "Поставщик шин и дисков", "address": "Украина, Днепропетровск, Днепропетровская область, ул.Артема а", "emailArray": [ "info@r25.com.ua" ], "phoneArray": [ "380669811060", "380671911865" ], "urlArray": [], "tags": "шины,диски,поставщик", "comment": null, "source": "tyetraer.ua" }{ "type": "company", "company": "R20", "position": "Поставщик шин и дисков", "address": "Украина, Днепропетровск, Днепропетровская область, ул.Артема а", "emailArray": [ "info@r25.com.ua" ], "phoneArray": [ "380669811060", "380671911865" ], "urlArray": [], "tags": "шины,диски,поставщик", "comment": null, "source": "tyetraer.ua" } 

I think you need something to "provide" in the syntax. Tell me please what is invalid?

  • Well, you have two JSON objects here, and you work with it as with one. Either parse the string manually and generate normal json-objects, or alter the file so that it contains 1 json-object, which will be an array of your records - BOPOH

1 answer 1

In JSON, you must use a single root element. Therefore, to make the second example valid, you can wrap objects in an array:

 [ { "type": "company", "company": "R20", "position": "Поставщик шин и дисков", "address": "Украина, Днепропетровск, Днепропетровская область, ул.Артема а", "emailArray": [ "info@r25.com.ua" ], "phoneArray": [ "380669811060", "380671911865" ], "urlArray": [], "tags": "шины,диски,поставщик", "comment": null, "source": "tyetraer.ua" }, { "type": "company", "company": "R20", "position": "Поставщик шин и дисков", "address": "Украина, Днепропетровск, Днепропетровская область, ул.Артема а", "emailArray": [ "info@r25.com.ua" ], "phoneArray": [ "380669811060", "380671911865" ], "urlArray": [], "tags": "шины,диски,поставщик", "comment": null, "source": "tyetraer.ua" } ]