Jump to content

Recommended Posts

Searching how to access javascript
find few code by @genius257 & @Danyfirex
and this link https://www.autoitscript.com/forum/topic/156794-oo_jsonudf-jsonpath-oo-using-javascript-in-auto-it/

#include "Json2.au3"

;__Example_2()
;__Example_3()
__Example_4()
;__Example_5()
;__Example_6()
;__Example_7()

Func __Example_2()
    Local $Js_String = '{"name":"John","cars":{"A": "Ford","B": "BMW","C": "Fiat","D": "Chevy"}}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $0_Carsobj = $ParseJson.cars
    ConsoleWrite('1st item(A)-> ' & $0_Carsobj.item("A") & @Crlf)
    ConsoleWrite('1st item(B)-> ' & $0_Carsobj.item("B") & @Crlf)
    ConsoleWrite('1st item(C)-> ' & $0_Carsobj.C & @Crlf)
    ConsoleWrite('1st item(D)-> ' & $0_Carsobj.D & @Crlf)
EndFunc

Func __Example_3()
    Local $Js_String = '{"Company":"ABC","Model":[{"Car":"Ford","Color":"Red"},{"Car":"BMW","Color":"Blue"},' & _
                       '{"Car":"Fiat","Color":"Green"},{"Car":"Chevy","Color":"Black"}],"Price":0.00}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Model = $ParseJson.Model
    For $i = 0 To $Get_Model.length - 1
        ConsoleWrite($i & ': ' & $Get_Model.item($i).Car & @Tab)
        ConsoleWrite($Get_Model.item($i).Color & @CRLF)
    Next
EndFunc

Func __Example_4()
    Local $Js_String = '{"Company":"ABC","Data":[["A1",0.70],["B1",0.80],["C1",0.90],["D1",1.00]],"Plot":"No"}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Model = $ParseJson.Data
    Local $oData
    For $i = 0 To $Get_Model.length - 1
    $oData = $Get_Model.item($i)
        For $j = 0 To $oData.length - 1
            ConsoleWrite($oData.item($j) &  @Tab)
        Next
        ConsoleWrite(@CRLF)
    Next
EndFunc

Func __Example_5()
    Local $Js_String = '{"status":"OK","data":["156,195.75,265","157,295.95,365","158,395.95,465"]}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Data = $ParseJson.data
    For $i = 0 To $Get_Data.length - 1
        ConsoleWrite($Get_Data.item($i) & @Crlf)
    Next
EndFunc

Func __Example_6()
    Local $Js_String = '{"status":200,"payload":{"Name":"ABC","data":[[156,131,187],[157,132,188],[158,133,189]]}}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Data = $ParseJson.payload.data
    Local $oData
    For $i = 0 To $Get_Data.length - 1
    $oData = $Get_Data.item($i)
        For $j = 0 To $oData.length - 1
            ConsoleWrite($oData.item($j) &  @Tab)
        Next
        ConsoleWrite(@CRLF)
    Next
EndFunc

Func __Example_7()
    Local $Js_String = '{"status":"ok", "data":{ "Value":[["2019-04-04",712,146],["2019-04-05",713,147],["2019-04-06",714,148]]}}'
    Local $JsObj = __JsonObject()
    Local $ParseJson = __JsonParse($JsObj, $Js_String)
    If @Error Then Exit

    Local $Get_Data = $ParseJson.data.Value
    Local $oData
    For $i = 0 To $Get_Data.length - 1
    $oData = $Get_Data.item($i)
        For $j = 0 To $oData.length - 1
            ConsoleWrite($oData.item($j) &  @Tab)
        Next
        ConsoleWrite(@CRLF)
    Next
EndFunc

Json2.au3

Edited by jugador
Link to post
Share on other sites

Json parse using ScriptControl Method is fast but consuming too much memory while parsing big json file.
and also not freeing memory even after parsing method is complete/done.

I didn't able to solve the (memory increasing)puzzle.
It will be great if someone have solution of this memory increasing problem of the above code.

besides as per stackoverflow.com search

Quote

ScriptControl-based approachs makes the system vulnerable in some cases,
since they allows a direct access to the drives (and other stuff) for the malicious JS code via ActiveX's.


So try to parse json using ObjCreate("htmlfile") and succeed :) .
speed almost same comparison to ScriptControl method
important part Memory usage normal.

Edited by jugador
Link to post
Share on other sites

@Jos  when you run the above code(1st post).... memory not cooling off even after function is done.
is it Autoit ObjCreate or "ScriptControl" method or the code problem.

someone else also posted about ObjCreate("ScriptControl") problem
link ->  https://www.autoitscript.com/forum/topic/203446-5-lines-script-and-guidelete-crashes/

what's the reason.
Thanks.

Edited by jugador
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...