![](/img/trans.png)
[英]PrincipalContextSearcher not returning correct results on extended principal type
[英]JsonValue.Parse not returning correct results
我试图解析这可以在这里找到一个以.json文件- http://files.star-made.org/releasebuildindex.json在这个片段我在此网站上发现-
WebClient webClient = new WebClient();
dynamic result = JsonValue.Parse(new WebClient().DownloadString("http://files.star-made.org/releasebuildindex.json"));
Console.WriteLine(result.builds.version);
使用文件的当前版本(每周更新一次,或每2个游戏更新更新一次),它应该返回字符串“ 0.163”,但当前返回的是“默认”,经过一番摸索之后,如果该标签返回了该值实际上不存在。
我不了解Json,并且不能编辑该文件,因为我不是它的创建者,非常感谢您的协助。
-詹姆士
构建是一个数组。 您将获得如下版本:
Console.WriteLine(results.builds[0].version);
要探究json字符串的结构,可以使用http://json2csharp.com/ 。
动态关键字是不错的选择,但是最好具有静态代码检查和自动完成功能。 为此,您需要具有POCO(普通旧CLR(公共语言运行时)对象)。
复制Json和Paste special-> Paste作为json类 (您至少需要Visual Studio 2012.2 RC ):
public class Rootobject
{
public string indexfileversion { get; set; }
public string type { get; set; }
public Build[] builds { get; set; }
}
public class Build
{
public string version { get; set; }
public string build { get; set; }
public string rawVersion { get; set; }
public string path { get; set; }
}
然后,您可以使用:
var json = new WebClient()
.DownloadString("http://files.star-made.org/releasebuildindex.json");
var result = new JavaScriptSerializer().Deserialize<Rootobject>(json);
Console.WriteLine(result.builds[0].version);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.