但我有这种JSON数据..
{
"returnCode": "success",
"Data": {
"results": [
{
"moredetails": [
{
"newoffers": [
],
"recentoffers_count": 0,
"sku": "30072246"
},
{
"newoffers": [
{
"availability": "Available",
"currency": "USD"
}
]
},
{
"newoffers": [
{
"availability": "Available",
"currency": "USD"
}
],
"offers_count": 1,
"name": "google.com"
}
],
..."features": {
..
},
"length": "20",
"geo": [
"usa"
],
.."images": ["http://timenerdworld.files.wordpress.com/2013/01/wpid-photo-jan-14-2013-1117-am.jpg"],
..
}
],
...
}
}
我的问题是我在JSONArray中有图像..
同样在java(android)中我这样做了.. 像这样解析..
JSONArray images = c.getJSONArray("images");
for(int s=0;s<images.length();s++)
{
map.put("images", images.getString(s));
}
之后它在android中运行良好..
现在在C#..
我做了解析get,set
methoid ..
但是在这里,图像在JSONarray内部
我正在使用像这样的图像加载器功能..
ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri(root1.Data.results.images));
StackPanelBackground.Background = imageBrush;
因为我知道只有这种代码..
“图像”: “http://timenerdworld.files.wordpress.com/2013/01/wpid-photo-jan-14-2013-1117-am.jpg”
不是这种
“images”:[“http://timenerdworld.files.wordpress.com/2013/01/wpid-photo-jan-14-2013-1117-am.jpg”]
在C#中,我需要更改哪些内容才能显示图像..
在Windows Phone 8中我通过这种方式解析json ..
public class Moredetail
{
public List[object] newoffers { get; set; }
public int recentoffers_count { get; set; }
public string sku { get; set; }
public int? offers_count { get; set; }
public string name { get; set; }
}
public class Result
{
public List [Moredetail] moredetails { get; set; }
public string length { get; set; }
public List[string] geo { get; set; }
public List[string] images { get; set; }
}
public class Data
{
public List[Result] results { get; set; }
}
public class RootObject
{
public string returnCode { get; set; }
public Data Data { get; set; }
}
我按照Displaying image and parsing json
的说法进行操作我从服务器获取数据..我已经在android上做了这个我想在windows phone 8中构建相同的... 任何Sugession
答案 0 :(得分:2)
使用JSON.NET可以获得像
这样的图像数组var j = JObject.Parse(yourJsonString);
var images = (JArray)j.SelectToken("results").SelectToken("images");
并且第一张图片是
var firstImageUrl = images.First().ToString();
所以你可以使用
mageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri(firstImageUrl));
StackPanelBackground.Background = imageBrush;