在C#中解析Json映像的问题 [英] Issue in Parsing Json image in C#

查看:147
本文介绍了在C#中解析Json映像的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

net C#.我正在尝试从Web服务解析Json.我已经用文本完成了,但是解析图像时遇到了问题.这是我从中获得Json的网址

net C#. I am trying to parse Json from a webservice. I have done it with text but having a problem with parsing image. Here is the Url from where I m getting Json

http://collectionking.com/rest/view/items_in_collection.json?args=122

这是我解析它的代码

using (var wc = new WebClient()) {
JavaScriptSerializer js = new JavaScriptSerializer();
var result = js.Deserialize<ck[]>(wc.DownloadString("http://collectionking.com/rest/view/items_in_collection.json args=122"));
foreach (var i in result) {
lblTitle.Text = i.node_title;
imgCk.ImageUrl = i.["main image"];
lblNid.Text = i.nid;

任何帮助都会很棒. 提前致谢. PS:它返回标题和Nid,但不返回图像. 我的课如下:

Any help would be great. Thanks in advance. PS: It returns the Title and Nid but not the Image. My class is as follows:

public class ck
{    
public string node_title;
public string main_image;
public string nid;  }

推荐答案

尝试一下

 private static string ExtractImageFromTag(string tag)
 {
 int start = tag.IndexOf("src=\""),
    end = tag.IndexOf("\"", start + 6);
return tag.Substring(start + 5, end - start - 5);
}
private static string ExtractTitleFromTag(string tag)
{
int start = tag.IndexOf(">"),
    end = tag.IndexOf("<", start + 1);
return tag.Substring(start + 1, end - start - 1);
}

可能有帮助

这篇关于在C#中解析Json映像的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆