本文介紹如何使用asp解析json字串,大家都知道asp對json的處理沒有php那麼簡單,也沒有索引值對數組,這可能也是它最終被php取代的直接原因。
下面代碼經本人測試可用,
代碼如下:
Dim scriptCtrlFunction parseJSON(str) If Not IsObject(scriptCtrl) Then Set scriptCtrl = Server.CreateObject("MSScriptControl.ScriptControl") scriptCtrl.Language = "JScript" scriptCtrl.AddCode "Array.prototype.get = function(x) { return this[x]; }; var result = null;" End If scriptCtrl.ExecuteStatement "result = " & str & ";" Set parseJSON = scriptCtrl.CodeObject.resultEnd FunctionDim jsonjson = "{a:""aaa"", b:{ name:""bb"", value:""text"" }, c:[""item0"", ""item1"", ""item2""]}"Set obj = parseJSON(json)Response.Write obj.a & "<br />"Response.Write obj.b.name & "<br />"Response.Write obj.c.length & "<br />"Response.Write obj.c.get(0) & "<br />"Set obj = NothingSet scriptCtrl = Nothing
本文由topic.alibabacloud.com提供,
文章地址:http://www.php.cn/csharp-article-377133.html
學編程就來topic.alibabacloud.com www.php.cn