我在windows phone 8应用程序工作。我有一些JSON文件在我的项目。他们有html扩展。我想解析这些文件并获取内容,请帮忙。
[
{ "heading":"Employee details",
"Sub":
[
{
"Name":"james",
"id":"ID1"
},{
"Name":"varun",
"id":"ID2"
},{
"Name":"francis",
"id":"ID4"
}
]
}
]
我已经尝试了以下代码
WebClient webClient = new WebClient();
Uri uri = new Uri("http://Contents/details.html");
webClient.OpenReadCompleted +=webClient_OpenReadCompleted;
webClient.OpenReadAsync(uri);
void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
DataContractJsonSerializer ser = null;
try
{
ser = new DataContractJsonSerializer(typeof(ObservableCollection<RootObject>));
ObservableCollection<RootObject> details = ser.ReadObject(e.Result) as ObservableCollection<RootObject>;
foreach (RootObject em in details)
{
string name = em.Name;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.InnerException.Message);
}
}
}
尝试使用NewtownSoft DLL解析JSON