如何解析我得到的Json字符串作为响应,将数据分开并存储在不同的变量中?

时间:2012-04-04 19:30:47

标签: json windows-phone-7

{“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”:“高达20%的折扣”},{“OFFER_ID”:“487 “,”OFFER_IMAGE“:”http://www.discountbox.in/DiscountBoxUpload/19373615.JPG“,”OFFER“:”高达40%的折扣“},{”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":"低至10%折扣“},{”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“:”平10%“},{”OFFER_ID “:” 481" , “OFFER_IMAGE”:“http://www.discount box.in/DiscountBoxUpload/13783976.JPG","OFFER":"Flat 20%Off“},{”OFFER_ID“:”480“,”OFFER_IMAGE“:”http://www.discountbox.in/DiscountBoxUpload/77105375 .jpg“,”OFFER“:”平8折“},{”OFFER_ID“:”479“,”OFFER_IMAGE“:”http://www.discountbox.in/DiscountBoxUpload/91484956.jpg“,”OFFER“ :“高达50%的折扣”},{“OFFER_ID”:“478”,“OFFER_IMAGE”:“http://www.discountbox.in/DiscountBoxUpload/25738727.jpg”,“OFFER”:“Bumper Dhamaka”}] }

我需要将OfferID,Image和Offer的数据存储在不同的变量中。 有没有办法在Visual Studio 2010 Express for Windows Phone中执行此操作。请帮助。 提前致谢

1 个答案:

答案 0 :(得分:0)

使用http://json2csharp.com/创建要反序列化的类。

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; }
}

然后,使用Json.NET

var deserializedProduct = JsonConvert.DeserializeObject<OfferResponse>(json);