Home  >  Article  >  Backend Development  >  How asp parses json string and converts it into asp object

How asp parses json string and converts it into asp object

PHP中文网
PHP中文网Original
2017-08-19 16:21:333532browse

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: //www.php.cn/csharp-article-377133.html

Come to PHP Chinese website to learn programming www.php.cn

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn