我想在C#中使用Newtonsoft JsonConvert将javascript数组序列化为对象。任何帮助将不胜感激。
我的Javascript数组对象是:
[
{
"ID": 0,
"Patient_ID": 1,
"Appointment_ID": 219,
"ObservationID": "33",
"arrOption": "{\"ObservationOptionList\":[{\"Observations_Param_Option_ID\":\"77\",\"Extended_Value\":\"\"}]}"
},
{
"ID": 0,
"Patient_ID": 1,
"Appointment_ID": 219,
"ObservationID": "1",
"arrOption": "{\"ObservationOptionList\":[{\"Observations_Param_Option_ID\":\"1\",\"Extended_Value\":\"Dry\"}]}"
},
{
"ID": 0,
"Patient_ID": 1,
"Appointment_ID": 219,
"ObservationID": "8",
"arrOption": "{\"ObservationOptionList\":[{\"Observations_Param_Option_ID\":\"25\",\"Extended_Value\":\"\"}]}"
},
{
"ID": 0,
"Patient_ID": 1,
"Appointment_ID": 219,
"ObservationID": "15",
"arrOption": "{\"ObservationOptionList\":[{\"Observations_Param_Option_ID\":\"40\",\"Extended_Value\":\"\"}]}"
}
]
答案 0 :(得分:1)
我认为你的意思是 de -serialize。
创建一个班级来容纳每位患者。
public class Patient
{
public int ID { get; set; }
public int Patient_ID { get; set; }
public int Appointment_ID { get; set; }
public string ObservationID { get; set; }
public string arrOption { get; set; }
}
反序列化为患者名单。
var patients = JsonConvert.DeserializeObject<List<Patient>>(json);
答案 1 :(得分:-1)
class MyClass
{
public int ID {get;set;}
public int Patient_ID {get;set;}
public int Appointment_ID {get;set;}
public string ObservationID {get;set;}
public string arrOption {get;set;
}
new JavaScriptSerializer().Deserialize<MyClass>(jsonString);
如果您还希望将
arrOption
反序列化为反序列化后需要预告的对象