gpt4 book ai didi

c# - 如何在 Windows Phone 8 中解析 Json 数组中的图像?

转载 作者:太空宇宙 更新时间:2023-11-03 10:51:13 25 4
gpt4 key购买 nike

我从 this link 开始关注如何在 Windows Phone 中从 url 解析 json 数据和 this link

但我有这种 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 方法完成了解析..但是这里的图像在 JSONarray 中

我正在使用这样的图像加载器功能..

ImageBrush imageBrush = new ImageBrush();
imageBrush.ImageSource = new BitmapImage(new Uri(root1.Data.results.images));
StackPanelBackground.Background = imageBrush;

据我所知,只有这种代码......

"images":"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 中构建相同的..任何建议

最佳答案

使用 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;

关于c# - 如何在 Windows Phone 8 中解析 Json 数组中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21349040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com