1
    The Code like this:
string jsonString = "{ \"array\": [[1.44,22,33], [1.445,2222,3333]]" +
                    "\"object\": {\"key1\":\"value1\", \"key2\":256}, " +
                    "\"string\": \"The quick brown fox \\\"jumps\\\" over the lazy dog \", " +
                    "\"unicode\": \"\\u3041 Men\\u00fa sesi\\u00f3n\", " +
                    "\"int\": 65536, " +
                    "\"float\": 3.1415926, " +
                    "\"bool\": true, " +
                    "\"null\": null }";

//Dictionary<string, object> dict = MiniJSON.LC_MiniJson.Deserialize(jsonString) as Dictionary.<string. Object>;
Dictionary<string, object> dict = MiniJSON.LC_MiniJson.Deserialize(jsonString) as Dictionary<string, object>;
Debug.Log("deserialized: " + dict.GetType());
//List<object> lst = (dict["array"]) as   List<object>;

Debug.Log("dict['array'][0]: " + (((dict["array"]) as List<object>)[0]));
Debug.Log("dict['string']: " + dict["string"].ToString());
Debug.Log("dict['float']: " + dict["float"]); // floats come out as doubles
Debug.Log("dict['int']: " + dict["int"]); // ints come out as longs
Debug.Log("dict['unicode']: " + dict["unicode"].ToString());

Dictionary<string, object> dict2 = (dict["object"]) as Dictionary<string, object>;

string str = MiniJSON.LC_MiniJson.Serialize(dict2);

现在我想获得“数组”的值。我不知道如何使用 minijson 获取值。谁经历过?

4

1 回答 1

1

答案在代码中。

((dict["array"]) as List<object>)[0]

这将返回数组中的值。如果要创建列表,可以执行以下操作:

var dict = Json.Deserialize(jsonString) as Dictionary.<String,System.Object>;

var arrayList = new List.<System.Object>();
arrayList = ((dict["array"]) as List.<System.Object>);

Debug.Log("array[0]: "+arrayList[0]);

您也可以像在 javascript 中一样访问该变量,例如:Debug.Log(data.array[0]); Debug.Log(data.object.key1);,但您需要为该 json 字符串创建一个类。见:https ://gist.github.com/Edudjr/cb407c67e76ac36bcfac#file-classminijson-js

于 2014-09-03T05:24:27.887 回答