我收到一个JSON obejct来使用MVC4启动一个Web会话.我需要将它解析为C#对象以供以后使用.我不能改变我收到的对象 - 它来自第三方.
我用来解析的方法:
MyClass jsonObject = new MyClass();
//The 2 lines below will not work with the given answer
//JavaScriptSerializer serializer = new JavaScriptSerializer();
//jsonObject = serializer.Deserialize<MyClass >(jsonString);
//Use this method instead
jsonObject = JsonConvert.DeserializeObject<MyClass>(jsonString);
Run Code Online (Sandbox Code Playgroud)
问题: 由于内部对象的"0"名称,我无法为JSON的这一部分定义C#类.
JSON:
{
"header": {
"to": {
"data": [],
"0": {
"data": [],
"value": "1101",
"domain": "DUNS"
}
},
"from": {
"data": [],
"0": {
"data": [],
"value": "1101",
"domain": "NetworkID"
}
},
"sender": {
"data": {
"UserAgent": "Test Client v1"
}, …Run Code Online (Sandbox Code Playgroud)