This article introduces how to use asp to parse json strings. Everyone knows that asp's processing of json is not as simple as php, and there is no key-value pair array. This may be the direct reason why it was eventually replaced by php.
The following code has been tested by me and is available.
The code is as follows:
Dim scriptCtrl Function 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.result End Function Dim json json = "{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 = Nothing Set scriptCtrl = Nothing
This article is provided by PHP Chinese website,
Article address: http: //m.sbmmt.com/csharp-article-377133.html
Come to PHP Chinese website to learn programming m.sbmmt.com
The above is the detailed content of How asp parses json string and converts it into asp object. For more information, please follow other related articles on the PHP Chinese website!