Deserialize json array to wp7 list

I need to get data from a subrange inside json, but not convert it to the list below, this is my json string

{"responseCode": "0", "responseObject": {"TotalRecords": 25, "TotalDisplayRecords": 25, "aaData": [{"InvoiceId": 16573, "somedata ..}", appCrmAccount (some names, total of 100 such names) amount ": 40086.00," invoiceNumber ":" 12, accountName ":" dfgAsfsadf "," dueDateStr ":" 04/24/2012 "(data must be in the list)

here is my code:

var djson = new DataContractJsonSerializer(typeof(dataList));
var stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
dataList result = (dataList)djson.ReadObject(stream);//not getting execute

kind help .. Thanks in Advance.

+3
source share
3 answers

, , DataContract DataMember

[DataContract] 
public class mainresponse
 {
 [DataMember]
 public resultmap arrayelement { get; set; }
 }  
 [DataContract]
 public class resultmap 
{
 [DataMember] 
 public string substringhere { get; set; } 
 }     
 var djson = new DataContractJsonSerializer(typeof(Mainresponse));
 var stream = new MemoryStream(Encoding.UTF8.GetBytes(responsestring));
 mainresponse result = (mainresponse)djson.ReadObject(stream);  

...

0

private void btnAdd_Click(object sender, RoutedEventArgs e)
{
    WebClient proxy = new WebClient();
    proxy.DownloadStringCompleted += new DownloadStringCompletedEventHandler(proxy_DownloadStringCompleted);
    proxy.DownloadStringAsync(new Uri(""));
}

JSON, . DataContractJsonSrrializer List of Student.

void proxy_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    Stream stream = new MemoryStream(Encoding.Unicode.GetBytes(e.Result));

    DataContractJsonSerializer obj = new DataContractJsonSerializer(typeof(List<Student>));
    List<Student> result = obj.ReadObject(stream) as List<Student>;
    lstStudents.ItemsSource = result;
}
+1

You must mark all classes and properties of the DataContract and DataMember attributes. Using a piece of code, I created something like this:

[DataContract]
    public class Result
    {
        [DataMember(Name="responseCode")]
        public int Code { get; set; }

        [DataMember(Name="responseObject")]
        public ResponseObject Result { get; set; }
    }

    [DataContract]
    public class ResponseObject
    {
        [DataMember]
        public int TotalRecords { get; set; }

        [DataMember]
        public int TotalDisplayRecords { get; set; }

        [DataMember(Name="aaData")]
        public DataItem[] Data { get; set; }
    }

    [DataContract]
    public class DataItem
    {
        [DataMember(Name = "InvoiceId")]
        public int InvoiceId { get; set; }

        // Others properties
    }
0
source

All Articles