JObject,JArray的基本操作
程序员文章站
2022-04-01 19:21:00
引用:https://www.cnblogs.com/dacongge/p/6957074.html 1、JObject:基本的json对象 2、JObject:嵌套子对象(JObject嵌JObject) 3、JArray:基本json对象中的数组 4、JArray: 多个json对象数组 5、J ......
引用:https://www.cnblogs.com/dacongge/p/6957074.html
1、jobject:基本的json对象
/// <summary> /// gets the j object. /// </summary> /// <returns></returns> public jobject getjobject() { var obj = new jobject {{"name", "mark" } }; return obj; }
2、jobject:嵌套子对象(jobject嵌jobject)
/// <summary> /// gets the j object. /// </summary> /// <returns></returns> public jobject getjobject() { var obj = new jobject {{"name", "mark"}, {"age", 8 }}; var info = new jobject {{"phone", "132****7777"}, {"gender", "男"}}; obj.add("info", info); return obj; }
3、jarray:基本json对象中的数组
/// <summary> /// gets the j array. /// </summary> /// <returns></returns> public jarray getjarray() { var jarray = new jarray(); var mark = new jobject { { "name", "mark" }, { "age", 8 } }; var jack = new jobject { { "name", "jack" }, { "age", 9 } }; jarray.add(mark); jarray.add(jack); return jarray; }
4、jarray: 多个json对象数组
/// <summary> /// gets the j array. /// </summary> /// <returns></returns> public jobject getjarray() { var obj = new jobject(); var student = new jarray { new jobject {{ "name", "mark" }, { "age", 8 } }, new jobject {{ "name", "jack" }, { "age", 9 } } }; var results = new jarray { new jobject {{ "subject", "语文"}, { "score", 100}}, new jobject {{ "subject", "数学" }, { "score", 88}} }; obj.add("student", student); obj.add("results", results); return obj; }
5、jarray:json数组嵌套数组(一个学生对应多个课程分数)
/// <summary> /// gets the results. /// </summary> /// <returns></returns> public jobject getresults() { var mark = new jobject { { "name", "mark" }, { "age", "8" } }; var results = new jarray { new jobject {{ "subject", "语文"}, { "score", 100}}, new jobject {{ "subject", "数学" }, { "score", 88}} }; mark.add("results", results); return mark; }
上一篇: 历史上张贵妃有几个孩子?张贵妃的孩子结局分别如何?
下一篇: 一些常遇到的概念名称