2

I need to deserialize some JSON objects. I tried to use Tiny-json library, but it's too slow. I tried to use Newtonsoft.Json, but it fails in webplayer with this error:

MissingMethodException: Method not found: 'System.Collections.ObjectModel.KeyedCollection.

What JSON parser do you recommend?

naktinis
  • 3,957
  • 3
  • 36
  • 52
Knaus Irina
  • 789
  • 5
  • 15
  • 35

2 Answers2

2

Unity 5.3 added Native support of Json Serializer. It is faster than others.

JsonUtility.ToJson to convert a class to Json.

JsonUtility.FromJson to convert Json back to class.

For complete example and information regarding json arrays, see

Serialize and Deserialize Json and Json Array in Unity

Community
  • 1
  • 1
Programmer
  • 121,791
  • 22
  • 236
  • 328
  • It has some limitations but should do in most case. Main limitation is if your json has an array as top object then JsonUtility fails to parse. – Everts Apr 14 '16 at 10:10
  • @fafase. I mentioned that when I said "json arrays" and the array limitation problem is solved in the link I posted above.The post contains 2 answers. 1 = normal json and 2 = array json. I see no need to re-post the long solution over and over again when the-same question is asked. – Programmer Apr 14 '16 at 10:19
  • I use Unity 5.2.3p3. It`s not contains JsonUtility – Knaus Irina Apr 14 '16 at 11:17
  • I mentioned in my answer you need **5.3**. All you have to do is Update to 5.3.... – Programmer Apr 14 '16 at 11:22
  • Also keep in mind that JsonUtility does NOT support an array of arrays (even if it's not a top level object). – Squeazer Jun 07 '17 at 14:28
  • @Squeazer It does **not** out of the box but **can** be made to support json array. See the link in my answer. – Programmer Jun 07 '17 at 15:09
  • @Programmer As far as I can see, your answer only works for top level arrays. In my case I want to deserialize (and serialize) a GeoJSON object, which has a property that is an array of arrays ("coordinates"). Is this possible? Example: http://geojson.io/#id=gist:anonymous/1ab40fbd7911ee2fbcc8905815e0c838&map=19/46.55743/15.63705 – Squeazer Jun 08 '17 at 13:14
  • It can't de-serialize `List> coordinates;`. On the linked queation, go to the part where it says *"3.De-serializing Json with numeric properties"*. It talked about `SimpleJSON.cs` which might work. – Programmer Jun 09 '17 at 18:53
2

You can try one of these open source solutions:

Or go with paid ones:

Taras Leskiv
  • 1,835
  • 15
  • 33