我正在使用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);
}
}
}