मैं एक स्ट्रिंग है:Convert स्ट्रिंग, का उपयोग Json.Net
[
{
"key": "key1",
"value": "{'Time':'15:18:42','Data':'15:18:42'}",
"duration": 5
},
{
"key": "key1",
"value": "{'Time':'15:18:42','Data':'15:18:42'}",
"duration": 5
}
]
मॉडल में मेरी कक्षा:
public class CPacket
{
public string key { get; set; }
public string value { get; set; }
public int duration { get; set; }
}
मैं Json.Net उपयोग करते हैं, मैं स्ट्रिंग परिवर्तित करना चाहते हैं जेसन ओजेक्ट को झुकाओ।
CPacket c = JsonConvert.DeserializeObject<CPacket>(strPostData);
लेकिन यह त्रुटि:
An exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll but was not handled in user code
Additional information: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'QuoteAPI.Models.CPacket' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
ओह! आपका बहुत बहुत धन्यवाद! इसने काम कर दिया! :) –