How to deserialize below json array. unable to fetch the field_options values and array of field_options. i am using DataContractJsonSerializer to deserialize. I need to fetch the field_options like size then if field_type is dropdown i will required the values of field_options -> options -> lebel and checked value as well as include_blank_option.
string jsonString = @"[{""fields"":[{""label"":""Untitled"",""field_type"":""paragraph"",""required"":true,""field_options"":{""size"":""small""},""cid"":""c2""},{""label"":""Untitled"",""field_type"":""text"",""required"":true,""field_options"":{""size"":""small""},""cid"":""c6""},{""label"":""Untitled"",""field_type"":""dropdown"",""required"":true,""field_options"":{""options"":[{""label"":""kjhkjh"",""checked"":false},{""label"":"",hkjkhkj"",""checked"":false}],""include_blank_option"":true},""cid"":""c8""}]}]}";
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<field>));
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(jsonString));
var obj = (List<field>)ser.ReadObject(stream);
foreach (Person sp in obj[0].fields)
{
Response.Write(sp.cid + sp.field_type + sp.label + sp.required + "<BR>");
List<sizee> si = sp.field_options;
foreach (sizee sz in si)
{
Response.Write(sz.size);
}
}
[DataContract]
class field
{
[DataMember]
public List<Person> fields { get; set; }
}
[DataContract]
class Person
{
[DataMember]
public string label { get; set; }
[DataMember]
public string field_type { get; set; }
[DataMember]
public string required { get; set; }
[DataMember]
public string cid { get; set; }
[DataMember]
public List<sizee> field_options { get; set; }
}
[DataContract]
class sizee
{
[DataMember]
public string size { get; set; }
[DataMember]
public List<option> size { get; set; }
}
[DataContract]
class option
{
[DataMember]
public string checke { get; set; }
[DataMember]
public string label { get; set; }
}
many thanks in advance.