我有以下有效的JSON,我需要遍歷結果。我正在使用JSON.NET和C#。我能夠獲得SUCCESS的價值,但我不知道如何獲得任何指導都會有所幫助。使用JSON.NET循環瀏覽JSON結果
{
"SUCCESS": 1,
"ERRMSG": "",
"COLUMNSANDDATA": {
"COLUMNS": ["LASTNAME", "FIRSTNAME", "EMAILADDRESS", "COURSENAME", "PROGRAMID",
"ENROLLMENTSTARTDATE", "COMPLETIONDATE", "GRADE", "SCORE",
"PASSED_NOTPASSED", "TYPEOFCREDITS", "CREDITSEARNED", "INSTRUCTORNAME",
"INSTRUCTOREMAILADDRESS", "CLIENTNAME", "COMMUNITYNAME",
"CERTIFICATESENTDATE", "DURATIONTYPE", "DURATIONMINUTES",
"LOGIN"],
"DATA": [
["Beane", "Coffee", "[email protected]", "Program with One Essay Test", null,
"January, 06 2014 18:06:56", "January, 06 2014 18:57:53", "Incomplete", null,
"Not Passed", "Musical Note", 0.00, "Ray Bradbury", "[email protected]",
"Hogarth's Flying Circus", "Captain's Club", null, null, null,
"[email protected]"],
["Beane", "Navy", "[email protected]", "Program with One Essay Test", null,
"January, 06 2014 18:06:56", "January, 06 2014 18:36:39", "Pass", 95.00,
"Passed", "Musical Note", 1.00, "Ray Bradbury", "[email protected]",
"Hogarth's Flying Circus", "Captain's Club", "January, 06 2014 08:00:00",
null, null, "NavyB"]
]
}
}
我能夠使用這個代碼塊
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
var deserializer = new JavaScriptSerializer();
var jsonObj = (IDictionary<string, object>)deserializer.DeserializeObject(result); ;
Response.Write((string)jsonObj["SUCCESS"]);
}
你確定你使用[Json.Net](http://www.newtonsoft.com/json)? ['JavaScriptSerializer'](https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer(v = vs.110).aspx)是Microsoft提供的類(不是Json.Net)。 –
是的。我安裝了JSON.NET,因爲我看過的很多示例都使用它。該項目最初是使用MS提供的類庫創建的。 –