How to parse a Json String which I m getting as a response to get the data separated and stored in different variable?

Go To StackoverFlow.com

0

{"OFFERS":[{"OFFER_ID":"490","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/19007012.JPG","OFFER":"Clearence Stock"},{"OFFER_ID":"488","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/36911135.JPG","OFFER":"Upto 20% Off"},{"OFFER_ID":"487","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/19373615.JPG","OFFER":"Upto 40% Off"},{"OFFER_ID":"486","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/16587130.JPG","OFFER":"Special Discount"},{"OFFER_ID":"485","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/56376547.JPG","OFFER":"Upto 10% Off"},{"OFFER_ID":"484","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/20302235.JPG","OFFER":"Free Eye Testing"},{"OFFER_ID":"483","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/14323344.JPG","OFFER":"Best Special Ra"},{"OFFER_ID":"482","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/19790443.JPG","OFFER":"Flat 10% Off"},{"OFFER_ID":"481","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/13783976.JPG","OFFER":"Flat 20% Off "},{"OFFER_ID":"480","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/77105375.jpg","OFFER":"Flat 20% Off"},{"OFFER_ID":"479","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/91484956.jpg","OFFER":"Upto 50% Off"},{"OFFER_ID":"478","OFFER_IMAGE":"http://www.discountbox.in/DiscountBoxUpload/25738727.jpg","OFFER":"Bumper Dhamaka"}]}

I need to get the data as OfferID, Image and Offer stored in different variables. Is there any way to do it in Visual Studio 2010 Express for Windows Phone.Please Help. Thanks in advance

2012-04-04 19:30
by anuj.bhartiya
Have you tried using Json.NET - Jon Skeet 2012-04-04 19:32
I dont know how to use it in my applicaton. :( Can u please help me about how to do it - anuj.bhartiya 2012-04-04 19:36


0

Use http://json2csharp.com/ to create a class to deserialize to.

public class OFFER
{
    public string OFFER_ID { get; set; }
    public string OFFER_IMAGE { get; set; }
    public string OFFER { get; set; }
}

public class OfferResponse
{
    public List<OFFER> OFFERS { get; set; }
}

Then, using Json.NET:

var deserializedProduct = JsonConvert.DeserializeObject<OfferResponse>(json);
2012-04-04 20:15
by Derek Beattie
I dont know how to use the Json.net...I m new to this thing...can you please help me - anuj.bhartiya 2012-04-04 20:28
That single line of code will deserialize the json you listed - Derek Beattie 2012-04-04 20:36
Ok. Now I got it. Really appreciate your help. Do you know how to then display this data on the phone?.. - anuj.bhartiya 2012-04-04 20:43
There are several ways,try a ListBox - Derek Beattie 2012-04-04 21:20
Ads