【发布时间】:2013-07-24 11:28:38
【问题描述】:
我是 windows phone 8 开发的新手...如何在 windows phone 8 中解析以下数据:
[
{
"detail":{
"single_selection":[
{
"Questions":"If -2<1\/2x< 4 , then",
"Question Type":"text",
"Url":"NO URL",
"options":{
"2379":"4 > x < -8",
"2380":"4 < x > -8",
"2381":"4 < x < -8",
"2382":"4 > x > -8"
},
"correct Ans":[
"2382"
],
"marks":"1",
"description":"4 > x > -8"
}
]
}
}
]
我正在尝试通过以下方式解析:
namespace TestSample
{
public partial class MainPage : PhoneApplicationPage
{
private const string Con_String = @"isostore:/DataBase.sdf";
// Constructor
public MainPage()
{
InitializeComponent();
Loaded += new RoutedEventHandler(MainPage_Loaded);
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri("SomeURL"));
}
public void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var rootObject = JsonConvert.DeserializeObject<RootObject1[]>(e.Result);
foreach (var r in rootObject)
{
var s = r.detail.single_selection;
for (int i = 0; i < s.Count; i++)
{
}
}
}
public class RootObject1
{
public Detail detail { get; set; }
[JsonProperty("total questions and marks")]
public List<TotalQuestionsAndMark> totalquestionsandmarks { get; set; }
}
public class TotalQuestionsAndMark
{
[JsonProperty("total questions")]
public int totalquestions { get; set; }
[JsonProperty("total test marks")]
public int totaltestmarks { get; set; }
public string Duration { get; set; }
}
public class Detail
{
public List<SingleSelection> single_selection { get; set; }
}
public class SingleSelection
{
public string Questions { get; set; }
[JsonProperty("Question Type")]
public string QuestionType { get; set; }
public string Url { get; set; }
public string marks { get; set; }
public string description { get; set; }
public Options option { get; set; }
[JsonProperty("correct Ans")]
public List<string> correctAns { get; set; }
}
public class Options
{
public string optionid { get; set; }
public string option_name { get; set; }
}
}
}
我能够解析一些数据,但我不知道如何解析选项..请帮助我解析完整的代码。请帮助我解析完整的数据......提前谢谢......
【问题讨论】:
-
抱歉,我的答案不正确,因此不得不删除。我认为您的问题是在“选项”参数中,JSON 使用映射键也作为您必须使用的值。我想你已经发现这是你遇到的问题。您可能可以使用 Json.NET 的序列化程序来找出这些位,但我没有使用它。 james.newtonking.com/projects/json/help/html/…
-
非常有帮助....
标签: c# json windows-phone-7 json.net