JsonWriter writer2 = new JsonWriter();
writer2.WriteObjectStart();
writer2.WritePropertyName("book");
writer2.WriteObjectStart();
writer2.WritePropertyName("title");
writer2.Write("android game!");
writer2.WritePropertyName("author");
writer2.Write("pei");
writer2.WritePropertyName("bookdetail");
writer2.WriteObjectStart();
writer2.WritePropertyName("pages");
writer2.Write(429);
writer2.WritePropertyName("about");
writer2.Write(null);
writer2.WriteObjectEnd();
writer2.WriteObjectEnd();
writer2.WriteObjectEnd();
Debug.Log(writer2.ToString());
这种方式非常不方便,不建议使用。
在使用LitJson中,建议使用JsonData,JsonMapper来处理Json的编码和解析。
Person[] p_array = { p,p,p};
string json_array=JsonMapper.ToJson(p_array);
Debug.Log(json_array);
JsonData pa = JsonMapper.ToObject(json_array);
Debug.Log(pa.IsArray+" "+pa.Count);
for (int i = 0; i < pa.Count;i++ )
{
Debug.Log(pa[i]["name"]+"-"+pa[i]["age"]+"-"+pa[i]["score"]+"-"+pa[i]["birth"]);
int age = int.Parse(pa[i]["age"].ToString());
Debug.Log(age);
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。
注:相关教程知识阅读请移步到c#教程频道。










