Need a JSON parser for Unity3d

2020-04-16 06:15发布

问题:

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?

回答1:

You can try one of these open source solutions:

  • https://github.com/jacobdufault/fullserializer
  • https://github.com/mtschoen/JSONObject (https://www.assetstore.unity3d.com/en/#!/content/710) I am using this one most of the times, it's versbose but does its job well, not sure about performance however

Or go with paid ones:

  • https://www.assetstore.unity3d.com/en/#!/content/11347


回答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



标签: json unity3d