C# 求这个通过Newtonsoft.Json解析json

问题描述

C# 求这个通过Newtonsoft.Json解析json

{
"isSuccess": true,
"errorMsg": "",
"timeStamp": "14",
"nonce": "13090713",
"sign": "3B732684B206EB3CE324E1E0FD4FAD368A638BD4",
"data": {
"msg": "",
"inkey": [
{
"paper_uid": "4bc8ebf2-7b1a-4952-a437-827810eaf78b",
"paper_name": "sater试卷",
"question_num": 6,
"total_score": "35",
"begin_time": "2015-03-02 16:31:16",
"allow_exam_time": "0",
"exam_grade_uid": "BD1972C5-6614-41E2-A270-D9C9DB1D509B",
"wait_time": 5,
"allow_showAnswer": "N",
"show_preQuestion": "Y",
"exam_do_mode_code": "46209b31-3154-4f1a-88e0-c286ba3fcdc9"
},
[
{
"paper_node_name": "单选题",
"question_num": "2",
"question_score": "0",
"total_score": "5"
},
[
{
"question_uid": "f86fa985-7295-4f4f-892f-d0e910b36459",
"question_base_typec_code": "single",
"paper_question_score": "5",
"question_text": "选什么?A",
"standard_answer": "A",
"question_exam_time": 20
},
[
{
"select_answer_value": "A",
"select_answer_text": "1111"
},
{
"select_answer_value": "B",
"select_answer_text": "222"
},
{
"select_answer_value": "C",
"select_answer_text": "333"
},
{
"select_answer_value": "D",
"select_answer_text": "4444"
}
]
],
[
{
"question_uid": "a7c04502-32db-4918-b037-4b42a0034720",
"question_base_typec_code": "single",
"paper_question_score": "0",
"question_text": "单选题___选B",
"standard_answer": "B",
"question_exam_time": 20
},
[
{
"select_answer_value": "A",
"select_answer_text": "qqqqqq"
},
{
"select_answer_value": "B",
"select_answer_text": "wwwww"
},
{
"select_answer_value": "C",
"select_answer_text": "eeeee"
},
{
"select_answer_value": "D",
"select_answer_text": "rrrrrrrr"
}
]
]
],
[
{
"paper_node_name": "多选题",
"question_num": "1",
"question_score": "0",
"total_score": "8"
},
[
{
"question_uid": "6465e790-02db-41d5-a387-06156196c8f1",
"question_base_typec_code": "multi",
"paper_question_score": "8",
"question_text": "选什么?AB",
"standard_answer": "A|B",
"question_exam_time": 20
},
[
{
"select_answer_value": "A",
"select_answer_text": "aaaa"
},
{
"select_answer_value": "B",
"select_answer_text": "bbb"
},
{
"select_answer_value": "C",
"select_answer_text": "cccc"
},
{
"select_answer_value": "D",
"select_answer_text": "dddd"
}
]
]
],
[
{
"paper_node_name": "判断题",
"question_num": "1",
"question_score": "0",
"total_score": "12"
},
[
{
"question_uid": "48f09eaa-9a44-4960-8610-7ec138865943",
"question_base_typec_code": "judge",
"paper_question_score": "12",
"question_text": "判断---对的,",
"standard_answer": "Y",
"question_exam_time": 20
},
[
{
"select_answer_value": "N",
"select_answer_text": "错误"
},
{
"select_answer_value": "Y",
"select_answer_text": "正确"
}
]
]
],
[
{
"paper_node_name": "填空题",
"question_num": "1",
"question_score": "0",
"total_score": "5"
},
[
{
"question_uid": "72a40be5-b93a-46a0-a3e2-d3a82e4d6d7f",
"question_base_typec_code": "fill",
"paper_question_score": "5",
"question_text": "填空___ok",
"standard_answer": "ok",
"question_exam_time": 20
},
[]
]
],
[
{
"paper_node_name": "问答题",
"question_num": "1",
"question_score": "0",
"total_score": "5"
},
[
{
"question_uid": "4d20a8a6-81ae-426f-bdfe-83c9d79848c1",
"question_base_typec_code": "answer",
"paper_question_score": "5",
"question_text": "问答题?嗯",
"standard_answer": "嗯",
"question_exam_time": 20
},
[]
]
]
]
}
}

解决方案

Newtonsoft.Json序列化和反序列
这里下载:http://www.newtonsoft.com/products/json/
安装:
1.解压下载文件,得到Newtonsoft.Json.dll
2.在项目中添加引用..
序列化和反序列在.net项目中:

Product product = new Product();

product.Name = "Apple";
product.Expiry = new DateTime(2008, 12, 28);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };

string output = javascriptConvert.SerializeObject(product);
//{
// "Name": "Apple",
// "Expiry": new Date(1230422400000),
// "Price": 3.99,
// "Sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}

Product deserializedProduct = (Product)javascriptConvert.DeserializeObject(output, typeof(Product));

读取JSON

string jsonText = "['JSON!',1,true,{property:'value'}]";

JsonReader reader = new JsonReader(new StringReader(jsonText));

Console.WriteLine("TokenTypettValueTypettValue");

while (reader.Read())
{
Console.WriteLine(reader.TokenType + "tt" + WriteValue(reader.ValueType) + "tt" + WriteValue(reader.Value))
}

结果显示:
TokenType ValueType Value
StartArray null null
String System.String JSON!
Integer System.Int32 1
Boolean System.Boolean True
StartObject null null
PropertyName System.String property
String System.String value
EndObject null null
EndArray null null
JSON写入

StringWriter sw = new StringWriter();
JsonWriter writer = new JsonWriter(sw);

writer.WriteStartArray();
writer.WriteValue("JSON!");
writer.WriteValue(1);
writer.WriteValue(true);
writer.WriteStartObject();
writer.WritePropertyName("property");
writer.WriteValue("value");
writer.WriteEndObject();
writer.WriteEndArray();

writer.Flush();

string jsonText = sw.GetStringBuilder().ToString();

Console.WriteLine(jsonText);
// ['JSON!',1,true,{property:'value'}]

这里会打印出: ['JSON!',1,true,{property:'value'}].

解决方案二:

参考链接

http://www.cnblogs.com/sbxwylt/archive/2008/12/31/1366199.html

时间: 2024-08-02 12:19:40

C# 求这个通过Newtonsoft.Json解析json的相关文章

java json 解析-json字符串的取出问题

问题描述 json字符串的取出问题 别人给我发了一个json字符串,我想将其中的键值对一一取出.json里有我自定义类型的对象,和普通string类型的值,求教各位大神我应该怎么写这个方法. 解决方案 如果用java解析json的话,可以用json-lib进行解析,其实用法很简单,可以直接把json数据映射成自定义的java对象. 参考:http://blog.csdn.net/zhejingyuan/article/details/9180885 解决方案二: var json = '[{"i

IOS中Json解析实例方法详解(四种方法)_IOS

作为一种轻量级的数据交换格式,json正在逐步取代xml,成为网络数据的通用格式. 有的json代码格式比较混乱,可以使用此"http://www.bejson.com/"网站来进行JSON格式化校验(点击打开链接).此网站不仅可以检测Json代码中的错误,而且可以以视图形式显示json中的数据内容,很是方便. 从IOS5开始,APPLE提供了对json的原生支持(NSJSONSerialization),但是为了兼容以前的iOS版本,可以使用第三方库来解析Json. 本文将介绍Tou

Android json解析及简单例子_Android

一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据交换.JSON采用兼容性很高的文本格式,同时也具备类似于C语言体系的行为. – Json.org JSON Vs XML 1.JSON和XML的数据可读性基本相同 2.JSON和XML同样拥有丰富的解析手段 3.JSON相对于XML来讲,数据的体积小 4.JSON与JavaScript的交互更加方便 5.JSON对数

安卓小白 求大神解析json 求代码

问题描述 安卓小白 求大神解析json 求代码 { "date": "20140617", "stories": [ { "title": "千万不要干傻事", "ga_prefix": "09", "images": [ "http://www.baidu.com/img/baidu_sylogo1.gif" ], "

求高手解析json java的

问题描述 求高手解析json java的 {"data":[{"result":{"result":[{"data":["2","9","2","6","6"],"key":"ball"}]},"phasetype":"202","phas

Swift: 用Alamofire做http请求,用ObjectMapper解析JSON

跟不上时代的人突然间走在了时代的前列,果然有别样的风景.首先鄙视一下AFNetworking.这个东西实在太难用了.不想封装都不行,要不写一大堆代码. 1 2 3 4 5 6 7 8 9 10 11 NSURL *URL = [NSURL URLWithString:@"http://example.com/resources/123.json"]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; [man

ndr-Adnroid json解析取数组里的数组

问题描述 Adnroid json解析取数组里的数组 我想去到result中的index对象应该怎么取? 先取了result这个jsonArray 但是里面还有个jsonArray啊?,不知道怎么拿,求大神指导 { "error": 0, "status": "success", "date": "2015-01-16", "results": [ { "currentCity

json-关于gson解析Json数据出现错误

问题描述 关于gson解析Json数据出现错误 代码如下: private ResponseGetUserByUserId resp; public void onSuccess(int statusCode Header[] headers byte[] responseBody) { String jsonData = new String(responseBody); Log.d(TAGSuccess: "" + jsonData); resp = new Gson().from

ava json-用java的谷歌库gson解析JSON,如下的json数据,该如何定义java类??

问题描述 用java的谷歌库gson解析JSON,如下的json数据,该如何定义java类?? 求高人指点,用java的谷歌库gson解析JSON,如下的json数据,该如何定义java类?? 在线等............... { "00:00:8e:d7:ba:ac:88:47": { "flow-mod-3": { "version": 1, "type": "FLOW_MOD", "le