2013-04-25 93 views
-3

請幫我在這CONVER JSON到C#類如何將JSON轉換爲C#類(es)?

[{"size":[{"width":8,"height":8}]}, 
{"ppi":300,"theme":1}, 
{"cover":[{"type":"Hard Cover","title":"Photobook Title (Albumname)","image_url":"imagexyz.jpg"}]}, 
{"pages":[{"page":[{"pageid":"page0","layout":"one-tmp full",         "layout_type":"one-tmp full","background_image":"img/photobook/bg/12.jpg", 
    "photos":[{"id":"pg0-photo1","image_url":"https://images/stephy/w692-692h/b6964ed0-ea70-4176-ba0e-a32d607baec9.jpg", 
"crop":[{"width":617,"height":469,"top":0,"left":-1,"p_width":469,"p_height":469}]}]},    {"pageid":"page1","layout":"one-tmp full", "layout_type":"one-tmp full","background_image":"img/photobook/bg/12.jpg", 
"photos":[{"id":"pg1-photo1","image_url":"https://images/stephy/w876-547h/e0c369d2-5617-46d3-970c-f9998bef23c3.jpg", 
"crop":[{"width":617,"height":469,"top":0,"left": -1,"p_width":469,"p_height":469}]}]} 
]   }] }] 

我試圖從這個轉換this example,但它不能正常工作。它給了我一個JSON與該類對象不匹配的錯誤。請幫我轉換它,以及如何更改「封面」:[「image_url」]?

回答

1

你JSON是一個陣列,所以在使用你所提到的網站創建對象後,就試試這個

var obj = JsonConvert.DeserializeObject<List<RootObject>>(json); 

它將工作...