Home > Backend Development > C#.Net Tutorial > How asp parses json string and converts it into asp object

How asp parses json string and converts it into asp object

PHP中文网
Release: 2017-08-19 16:21:33
Original
3574 people have browsed it

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template