Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deserialize json array to list wp7

i need to get data from sub-array inside json,but its not getting converted into list, below is my json string

{"responseCode":"0","responseObject":{"TotalRecords":25,"TotalDisplayRecords":25,"aaData":[{"InvoiceId":16573,"somedata..}," appCrmAccount(some title,total 100 such titles) amount":40086.00,"invoiceNumber":"12,accountName":"dfgAsfsadf"," dueDateStr":"04/24/2012"(data to be get into 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

kindly help.. Thanks in Advance.

like image 465
Anand Avatar asked Jun 27 '26 08:06

Anand


1 Answers

Try this

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

And need to parse the returned JSON as below. In parameter to create instance of DataContractJsonSrrializer we are passing 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;
}
like image 186
SENTHIL KUMAR Avatar answered Jun 29 '26 21:06

SENTHIL KUMAR



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!