asp解析迭层,多层JSON代码
in 技术交流 with 1 comment

asp解析迭层,多层JSON代码

in 技术交流 with 1 comment

前几天遇到一个工程需要解析多层JSon 研究了弄半天出来,有需要拿去吧!

<% 
 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 obj    
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set htmlwrite=fso.OpenTextFile(server.MapPath("js.txt")) 
    strOut=htmlwrite.ReadAll 
    htmlwrite.close  
    Set obj = parseJSON(strOut)    

    Response.Write "解析后为"    
   Response.Write "<hr>"  

    Response.Write "code=" & obj.code & "<br />"   
    Response.Write "charge=" & obj.charge & "<br />" 
    Response.Write "words索引=0-" & obj.result.words_result.length-1 & "<br />"   
    for i = 0 to 5
        Response.Write "Words"&i&"=" & obj.result.words_result.get(i).words & "<br />"  
    next
    Set obj = Nothing    
%>    
Comments are closed.
  1. 还可以这样用