Jump to content
Ward

A Non-Strict JSON UDF (JSMN)

Recommended Posts

Ward

#Include "Json.au3"

Local $Json = '{ "Headers":[ { "Name":"LOGICAL_NAME","Type":"VARCHAR2"}],"ColumnCount":1,"Rows":[ { "Cells":[ "ThisIsWhatIWant"],"CellCount":1}]}'
Local $Obj = Json_Decode($Json)

ConsoleWrite(Json_Get($Obj, '["Rows"][0]["Cells"][0]') & @LF)
ConsoleWrite(Json_Get($Obj, '.Rows[0].Cells[0]') & @LF)

ConsoleWrite(Json_Encode($Obj, $JSON_PRETTY_PRINT) & @LF)

  • Like 1

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Share this post


Link to post
Share on other sites
mojomatt

Wow, for such a short script that's pretty complicated - but I get it now.  Thanks for your timely help Argumentum!  :thumbsup:

Share this post


Link to post
Share on other sites
mojomatt

Thanks Ward - I didn't realize I was using json_ObjGet instead of json_Get. Makes quite a bit of difference. Slick and easy!

Share this post


Link to post
Share on other sites
argumentum

Wow, for such a short script that's pretty complicated - but I get it now.  Thanks for your timely help Argumentum!  :thumbsup:

thanks, Ward's is the correct one, therefore I removed my answer to not confuse anyone in the future.

Share this post


Link to post
Share on other sites
argumentum

I'm learning JSON, so I wanted a ConsoleWriteJson( $StringJson ) , so I put it together, it may help the next guy ( you'd need to #include <JSON.au3> , but you know that. )

Edit1: I see I did not code anything in case of error.

Func ConsoleWriteJson($sJsonString, $sDesc = "", $iEcho = True)
    If $sDesc = "" Then $sDesc = 'ConsoleWriteJson'
    Local $obj = Json_Decode($sJsonString)
    Local $sOutGlobal = ""
    Return Json_Iterate($obj, '', $sOutGlobal, $sDesc, $iEcho)
EndFunc   ;==>ConsoleWriteJson

Func Json_Iterate($obj, $String, ByRef $sOutGlobal, $pre = "", $iEcho = True)
    Local $sOut = ""
    Local $temp, $i, $b
    If ($pre <> "") Then
        $sOutGlobal &= $pre & ": "
        If $iEcho Then ConsoleWrite($pre & ": ")
    EndIf
    $a = Json_Get_ShowResult($obj, $String, $sOutGlobal, $iEcho)
    If IsArray($a) Then
        For $i = 0 To UBound($a) - 1
            Json_Iterate($obj, $String & '[' & $i & ']', $sOutGlobal, $pre, $iEcho)
        Next
    ElseIf IsObj($a) Then
        $b = Json_ObjGetKeys($a)
        For $temp In $b
            Json_Iterate($obj, $String & '["' & $temp & '"]', $sOutGlobal, $pre, $iEcho)
        Next
    EndIf
    Return $sOutGlobal
EndFunc   ;==>Json_Iterate

Func Json_Get_ShowResult($Var, $Key, ByRef $sOutGlobal, $iEcho)
    Local $sOut = ""
    Local $Ret = Json_Getr($Var, $Key)
    If @error Then
        Switch @error
            Case 1
                $sOut &= "Error 1: key not exists" & @LF
                $sOutGlobal &= $sOut
                If $iEcho Then ConsoleWrite($sOut)
            Case 2
                $sOut &= "Error 2: syntax error" & @LF
                $sOutGlobal &= $sOut
                If $iEcho Then ConsoleWrite($sOut)
        EndSwitch
    Else
        $sOut &= $Key & " => " & VarGetType($Ret) & ": " & $Ret & @LF
        $sOutGlobal &= $sOut
        If $iEcho Then ConsoleWrite($sOut)
    EndIf
    Return $Ret
EndFunc   ;==>Json_Get_ShowResult

Func Json_Getr($Var, $Key)
    If Not $Key Then Return $Var
    Local $Match = StringRegExp($Key, "(^\[([^\]]+)\])", 3)
    If IsArray($Match) Then
        Local $Index = Json_Decode($Match[1])
        $Key = StringTrimLeft($Key, StringLen($Match[0]))
        If IsString($Index) And Json_IsObject($Var) And Json_ObjExists($Var, $Index) Then
            Local $Ret = Json_Getr(Json_ObjGet($Var, $Index), $Key)
            Return SetError(@error, 0, $Ret)
        ElseIf IsNumber($Index) And IsArray($Var) And $Index >= 0 And $Index < UBound($Var) Then
            Local $Ret = Json_Getr($Var[$Index], $Key)
            Return SetError(@error, 0, $Ret)
        Else
            Return SetError(1, 0, "")
        EndIf
    EndIf
    Return SetError(2, 0, "")
EndFunc   ;==>Json_Getr
Edited by argumentum

Share this post


Link to post
Share on other sites
FaridAgl

@Ward

I just come to say "Thank you so much" for this great UDF.
I'm using it for a while, saved my ass multiple times and I just felt I have to say "Thanks".

Thank you.

Edited by FaridAgl

Share this post


Link to post
Share on other sites
Jemboy

Thank you Ward for the time invested in this UDF, because I really do not understand the whole JSON thing yet :sweating:, so I am thankfull you do ;-)

I wanted to change some settings in the Chrome preferences-file, which turnout to be a JSON-file, so I am going to use your UDF! :) 

Share this post


Link to post
Share on other sites
Xplode

Hello,

It seems that having ExpandVarStrings or ExpandEnvStrings option set to 1 makes Json_encode() function crashes. I have to do this in order to make the function works :      

Opt("ExpandVarStrings",0)
Opt("ExpandEnvStrings",0)
Json_Encode($obj,$JSON_UNESCAPED_SLASHES))
Opt("ExpandVarStrings",1)
Opt("ExpandEnvStrings",1)

Otherwise the program simply crashes ( There is no AutoIT error, the program just crashes ). Are you aware of this possible bug ?

Regards. 

Edited by Xplode

Share this post


Link to post
Share on other sites
kyo

Ahh... working with JSON is so much easier tolerable now, thanks to you Ward!

I'm so glad I found this UDF!!

Share this post


Link to post
Share on other sites
AdamUL

The UDF is unavailable for download, and is not listed in Downloads.  Does any one know where I can get it?  

 

Thanks,

Adam

 

Share this post


Link to post
Share on other sites
AdamUL

argumentum, 

Thanks for uploading it.  

 

Adam

 

  • Like 1

Share this post


Link to post
Share on other sites
Jury

How do I list the last level of objects in the last level of keys?  As you can see I've commented out my last, of many, efforts.

 

#include "Json.au3"

$Json = '{"Air Elemental":{"layout":"normal","name":"Air Elemental","manaCost":"{3}{U}{U}","cmc":5,"colors":["Blue"],"type":"Creature — Elemental","types":["Creature"],"subtypes":["Elemental"],"text":"Flying","power":"4","toughness":"4","imageName":"air elemental","colorIdentity":["U"]},"Ancestral Recall":{"layout":"normal","name":"Ancestral Recall","manaCost":"{U}","cmc":1,"colors":["Blue"],"type":"Instant","types":["Instant"],"text":"Target player draws three cards.","imageName":"ancestral recall","colorIdentity":["U"]}'


$Obj = Json_Decode($Json)


If Json_IsObject($Obj) Then
    $Keys = Json_ObjGetKeys($Obj)
    For $i = 0 To UBound($Keys) - 1
        ConsoleWrite($Keys[$i] & @LF)

        $obects = Json_ObjGet($Obj, $Keys[$i])
        $KeysB = Json_ObjGetKeys($obects)

        For $h = 0 To UBound($KeysB) - 1
            ConsoleWrite('  ' & $KeysB[$h] & @LF)

;~          $obectsB = Json_ObjGet($obects, $KeysB[$h])
;~          $KeysC = Json_ObjGetKeys($obectsB)

;~          For $g = 0 To UBound($KeysC) - 1
;~              ConsoleWrite('      ' &  $KeysC[$g] & @LF)
;~          Next

        Next
    Next
EndIf

 

Edited by Jury

Share this post


Link to post
Share on other sites
argumentum

How do I list the last level of objects in the last level of keys?

according to http://stackoverflow.com/questions/4317456/getting-the-last-item-in-a-javascript-object

No. Order is not guaranteed in JSON and most other key-value data structures, 
so therefore the last item could sometimes be carrot and
at other times be banana and so on. If you need to rely on ordering, 
your best bet is to go with arrays. 
The power of key-value data structures lies in accessing values by
their keys, not in being able to get the nth item of the object.

or play around with ConsoleWriteJson  https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/?do=findComment&comment=1224189  above

Edit: I see that the string has game like values and if it's a bot, I just got me in trouble for helping, but you've been here since 2009 and would not even dream of that.

Edited by argumentum

Share this post


Link to post
Share on other sites
Jury

Thanks - I'm not interested in the string - I just got it off the internet as an example of json

http://mtgjson.com/

silly me I didn't even think of what it was. Sorry everyone.

 

 

  • Like 1

Share this post


Link to post
Share on other sites
Tipulatoid

Hello.
I wonder if there is a quick way to get key knowing only the array element.
Here is JSON string:

{"result":{"tree":{"36":{"1958":[989,1649,2066,659,616]},"4":{"2317":[886,2350,2219,1520,795,1352,809,2521],"1960":[2197,1628,1538,2332,1416],"489":[1277],"1289":[2213,25,2105,2214]},"34":{"2354":[1271],"2362":[1265,1266,1267,1358,2363,1268,1673,1269,1270,1275,2364,1276,1274],"1264":[2358,2359,2360,2361],"2057":[2355,2474,2356,2357],"2413":[1501,1580,525]},"10":{"610":[628,1568,1542,2335,1544,1545,1546,1549,1597,1552,1550,1553,1554,617,1555,2017,1257,1258,2208,677,1255,1479,1261,614,1259,2065,1254,1260,2209,2210,1547,1548,2211,615],"1581":[1582,1583,1590,1587,1594,1591,1588,1596,1585,1586,2078,1929,1593,1592,1595],"1556":[1557,1560,1561,1653,1570,1654,1655,1656,1930,1931,1932,1562,1563,1626,1564,1565,1559,1566,1573,1567]},"33":{"395":[396,2322,2167,1993,2321],"2326":[1036,400,574],"2389":[2387,2388],"2327":[695,399,402,490,499],"2324":[2325,2342,530,2152],"2328":[403,1279,716,2165,401]}}}}

I know only array element, for example, 1583. I need to get key - 10

Here is how I do that for now:

#Include <Array.au3>
#Include <Json.au3> ; https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn/

$iForumID = 1583
$sJSON = '{"result":{"tree":{"36":{"1958":[989,1649,2066,659,616]},"4":{"2317":[886,2350,2219,1520,795,1352,809,2521],"1960":[2197,1628,1538,2332,1416],"489":[1277],"1289":[2213,25,2105,2214]},"34":{"2354":[1271],"2362":[1265,1266,1267,1358,2363,1268,1673,1269,1270,1275,2364,1276,1274],"1264":[2358,2359,2360,2361],"2057":[2355,2474,2356,2357],"2413":[1501,1580,525]},"10":{"610":[628,1568,1542,2335,1544,1545,1546,1549,1597,1552,1550,1553,1554,617,1555,2017,1257,1258,2208,677,1255,1479,1261,614,1259,2065,1254,1260,2209,2210,1547,1548,2211,615],"1581":[1582,1583,1590,1587,1594,1591,1588,1596,1585,1586,2078,1929,1593,1592,1595],"1556":[1557,1560,1561,1653,1570,1654,1655,1656,1930,1931,1932,1562,1563,1626,1564,1565,1559,1566,1573,1567]},"33":{"395":[396,2322,2167,1993,2321],"2326":[1036,400,574],"2389":[2387,2388],"2327":[695,399,402,490,499],"2324":[2325,2342,530,2152],"2328":[403,1279,716,2165,401]}}}}'

ConsoleWrite (_GetAPICategoryID ($iForumID) & @CRLF)


Func _GetAPICategoryID ($iffAPIForumID)
    $Obj = Json_ObjGet(Json_ObjGet(Json_Decode($sJSON), "result"), "tree")
    $aTMP15 = Json_ObjGetKeys ($Obj)
    $iFoundCategoryID = ""
    For $i = 0 To UBound ($aTMP15) -1
        $Obj1 = Json_ObjGet ($Obj, $aTMP15[$i])
        $aTMP16 = Json_ObjGetKeys ($Obj1)
            For $x = 0 To UBound ($aTMP16) -1
                $aTMP17 = Json_Get ($Obj1, '["' & $atmp16[$x] & '"]')
                If _ArraySearch ($aTMP17, $iffAPIForumID) <> -1 Then
                    $iFoundCategoryID = $aTMP15[$i]
                    ExitLoop
                EndIf
            Next
        If $iFoundCategoryID  <> "" Then ExitLoop
    Next
    Return $iFoundCategoryID
EndFunc ; _GetAPICategoryID ()

But this is too slow and not gracefully. Maybe there is better way? Thank you in advance

Share this post


Link to post
Share on other sites
addjon

Hello. I want to say thank you for this UDF, I tried other, nothing worked. And this figured out thanks to the topic and running. But still faced with the problem and do not know how to do that. I hope will prompt

Have two json

json_1
{"response":{"status":1,"httpStatus":200,"data":[{"id":"10445","categories":{"6":{"id":"6","name":"D"},"27":{"id":"27","name":"I"}}},{"id":"10159","categories":{"20":{"id":"20","name":"W"}}}],"errors":[],"errorMessage":null}}

json_2
{"response":{"status":1,"httpStatus":200,"data":[{"id":"11930","countries":{"CH":{"id":"756","code":"CH","name":"Switzerland","regions":[]}}},{"id":"11928","countries":{"UK":{"id":"826","code":"UK","name":"United Kingdom","regions":[]},"HR":{"id":"191","code":"HR","name":"Croatia","regions":[]}}}],"errors":[],"errorMessage":null}}

from both must be received "name" in the first "categories", the second of the "countries"

my code

#include <Array.au3>
#include "JSON.au3"

$sJSON = FileRead(@ScriptDir & "\1.json")

$objJson = Json_Decode($sJSON)
$Response = Json_ObjGet($objJson, "response")
$Data = Json_ObjGet($Response, "data")
Local $N = UBound($Data)
Dim $List[$N]
    For $i = 0 To UBound($Data) - 1
        Local $objJson2 = $Data[$i]
        Local $Categories = Json_ObjGet($objJson2, "categories") ;or "countries" for json_2
        Local $nCat = Json_ObjGetKeys($Categories)
        Local $N = UBound($nCat)
        Dim $aCat[$N]
        For $j = 0 To UBound($nCat) - 1
            Local $objJson2 = Json_ObjGet($Categories, $nCat[$j])
            $aCat[$j] = Json_ObjGet($objJson2, "name")
        Next
        $strCat = ''
        For $j = 0 to UBound($aCat) - 1
            $strCat &= $aCat[$j] & ', ' 
        Next
        $strCat = StringTrimRight($strCat, 2)
        $List[$i] = $strCat 
     Next

_ArrayDisplay($List,"List")

For json_1 works fine. For json_2 function Json_ObjGetKeys an error

JSON.au3 "(342): ==> Variable must be of type" Object ".:
Return $ Object.Keys ()
Return $ Object ^ ERROR

I realized that the reason for this error is that the structure of "countries" objects letters "CH", "UK" and the like, and the structure of the "categories" - number
How do I get the data from "countries" in this situation?

Share this post


Link to post
Share on other sites
argumentum

@addjon, many ask for an Arrayfied Json. Here is my take at it, that works with your string. ( may not work with others )

#include <JSon.au3>
#include <Array.au3>

Local $sJson_1 = '{"response":{"status":1,"httpStatus":200,"data":[{"id":"10445","categories":{"6":{"id":"6","name":"D"},"27":{"id":"27","name":"I"}}},{"id":"10159","categories":{"20":{"id":"20","name":"W"}}}],"errors":[],"errorMessage":null}}'
Local $sJson_2 = '{"response":{"status":1,"httpStatus":200,"data":[{"id":"11930","countries":{"CH":{"id":"756","code":"CH","name":"Switzerland","regions":[]}}},{"id":"11928","countries":{"UK":{"id":"826","code":"UK","name":"United Kingdom","regions":[]},"HR":{"id":"191","code":"HR","name":"Croatia","regions":[]}}}],"errors":[],"errorMessage":null}}'

Local $aReturned = JsonArrayfied($sJson_1)
_ArrayDisplay($aReturned, "$aReturned")

$aReturned = JsonArrayfied($sJson_2)
_ArrayDisplay($aReturned, "$aReturned")

Func JsonArrayfied($sJsonString, $iEcho = 0)
    Local $sConsoleWriteJson = ConsoleWriteJson($sJsonString, "", $iEcho)
    Local $n, $aLines = StringSplit($sConsoleWriteJson, @LF, 1)
    Local $aTemp, $iRow = 0, $iCol = 0, $m, $aJsonArrayfied[UBound($aLines) + 1][100] ; a lazy but efficient way to go about it
    For $n = 1 To $aLines[0]
        If StringInStr($aLines[$n], ":") + 2 > StringLen($aLines[$n]) Then ContinueLoop
        $aLines[$n] = StringReplace($aLines[$n], "][", "|")
        $aLines[$n] = StringReplace($aLines[$n], "]", "|")
        $aLines[$n] = StringReplace($aLines[$n], "[", "|")
        $aTemp = StringSplit($aLines[$n], "|")
        $iRow += 1
        For $m = 1 To $aTemp[0] - 1
            If $iCol < $m Then $iCol = $m
            $aJsonArrayfied[$iRow][$m - 1] = StringReplace($aTemp[$m], '"', '')
        Next
        $aJsonArrayfied[$iRow][$aTemp[0] - 1] = StringTrimLeft($aTemp[$aTemp[0]], StringInStr($aTemp[$aTemp[0]], ":") + 1)
        $aJsonArrayfied[$iRow][0] = StringMid($aTemp[$aTemp[0]], 5, StringInStr($aTemp[$aTemp[0]], ":") - 5)
    Next
    $aJsonArrayfied[0][0] = $iRow
    $aJsonArrayfied[0][1] = $iCol
    ReDim $aJsonArrayfied[$iRow + 1][$iCol + 1]
    Return $aJsonArrayfied
EndFunc   ;==>JsonArrayfied

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; added by me

Func ConsoleWriteJson($sJsonString, $sDesc = "", $iEcho = 1)
    Local $sOutGlobal
    If $sDesc = "" Then $sDesc = 'ConsoleWriteJson'
    Local $obj = Json_Decode($sJsonString)
    Json_Iterate($sOutGlobal, $obj, '', $sDesc, $iEcho)
    Return $sOutGlobal
EndFunc   ;==>ConsoleWriteJson

Func Json_Iterate(ByRef $sOutGlobal, $obj, $string, $pre = "", $iEcho = 1)
    Local $sOut = ""
    Local $temp, $i, $b
    If ($pre <> "") Then
        $sOut &= $pre & ": "
        If $iEcho Then ConsoleWrite($pre & ": ")
    EndIf
    $a = Json_Get_ShowResult($obj, $string, $sOutGlobal, $iEcho)
    If IsArray($a) Then
        For $i = 0 To UBound($a) - 1
            Json_Iterate($sOutGlobal, $obj, $string & '[' & $i & ']', $pre, $iEcho)
        Next
    ElseIf IsObj($a) Then
        $b = Json_ObjGetKeys($a)
        For $temp In $b
            Json_Iterate($sOutGlobal, $obj, $string & '["' & $temp & '"]', $pre, $iEcho)
        Next
    EndIf
    Return $sOutGlobal
EndFunc   ;==>Json_Iterate

Func Json_Get_ShowResult($Var, $Key, ByRef $sOutGlobal, $iEcho)
    Local $sOut = ""
    Local $Ret = Json_Getr($Var, $Key)
    If @error Then
        Switch @error
            Case 1
                $sOut &= "Error 1: key not exists" & @LF
                If $iEcho Then ConsoleWrite($sOut)
            Case 2
                $sOut &= "Error 2: syntax error" & @LF
                If $iEcho Then ConsoleWrite($sOut)
        EndSwitch
    Else
        $sOut &= $Key & " => " & VarGetType($Ret) & ": " & $Ret & @LF
        If $iEcho Then ConsoleWrite($sOut)
    EndIf
    $sOutGlobal &= $sOut ;& $Ret
    Return $Ret
EndFunc   ;==>Json_Get_ShowResult

Func Json_Getr($Var, $Key)
    If Not $Key Then Return $Var
    Local $Match = StringRegExp($Key, "(^\[([^\]]+)\])", 3)
    If IsArray($Match) Then
        Local $Index = Json_Decode($Match[1])
        $Key = StringTrimLeft($Key, StringLen($Match[0]))
        If IsString($Index) And Json_IsObject($Var) And Json_ObjExists($Var, $Index) Then
            Local $Ret = Json_Getr(Json_ObjGet($Var, $Index), $Key)
            Return SetError(@error, 0, $Ret)
        ElseIf IsNumber($Index) And IsArray($Var) And $Index >= 0 And $Index < UBound($Var) Then
            Local $Ret = Json_Getr($Var[$Index], $Key)
            Return SetError(@error, 0, $Ret)
        Else
            Return SetError(1, 0, "")
        EndIf
    EndIf
    Return SetError(2, 0, "")
EndFunc   ;==>Json_Getr

Hope it helps to get what you look for.

  • Like 1

Share this post


Link to post
Share on other sites
Jury

argumentum,

Brilliant!  and here I was attempting to stuff json into an array with little success.  Attached is an example of my data - it takes some time but then the end is an array of over 20,000  lines. So much better and reliable than parsing using regular expressions etc.

Thanks ever so...

cma-cases.json

  • Like 1

Share this post


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

  • Similar Content

    • jesus40
      By jesus40
      Hello friends, I need help getting data from json. I read json from url into a variable.
      Is possible to get volume_USD value etc.  where product_id= "ETH-BTC", ? So I want get "37421.69109185" as variable.
      I think is better keeping it in the memory as variable. Or easier to convert it to db or csv?
       
       
      #include <Inet.au3> #include <json.au3> $URL="https://api.abucoins.com/products/stats" $data = _INetGetSource($URL) MsgBox("","",$data) $object=json_decode($data) local $i=0 while 1 $message=json_get($object,'[product_id]');???????????????????????????????? MsgBox("","volume_USD",$message) $i=$i+1 WEnd  
      the json structure is here:
      https://api.abucoins.com/products/stats
      [ { "product_id": "ETH-BTC", "last": "0.05202015", "open": "0.05009375", "high": "0.05250000", "low": "0.04872420", "volume": "47.77440456", "volume_BTC": 2.48523169, "volume_USD": 37421.69109185, "volume_7d": "364.40240341", "volume_30d": "3555.83377072", "change": "3.85" }, { "product_id": "LTC-BTC", "last": "0.01737490", "open": "0.01744636", "high": "0.01779000", "low": "0.01658091", "volume": "67.62762830", "volume_BTC": 1.17502328, "volume_USD": 17941.95920676, "volume_7d": "611.57893068", "volume_30d": "3881.57766044", "change": "-0.41" }, { "product_id": "ETC-BTC", "last": "0.00191846", "open": "0.00189001", "high": "0.00198000", "low": "0.00162741", "volume": "66.48327742", "volume_BTC": 0.12754551, "volume_USD": 1947.54976323, "volume_7d": "738.94495089", "volume_30d": "4090.74712156", "change": "1.51" }, { "product_id": "ZEC-BTC", "last": "0.03466163", "open": "0.03365452", "high": "0.03466163", "low": "0.03295811", "volume": "33.40101560", "volume_BTC": 1.15773364, "volume_USD": 17677.95599574, "volume_7d": "191.15953471", "volume_30d": "887.70158297", "change": "2.99" } ]  
       
    • satanico64
      By satanico64
      hi guys !
      how are you ? fine ? yeahhh
      Here is my problem:
      I have 2 autoit applications, a.exe and b.exe
      In a.exe, i call b.exe with a json as parameter:
      FileWrite("N:\+++ Dev\ClientServeur\FolderMonitor.nca", "lejson in A:" & Json_Encode($json_tmp)& @CRLF) Run(@ScriptDir & "\FolderMonitor.exe " & Json_Encode($json_tmp) )                        
              In program B:
      ;Firstline of program: FileWrite("N:\+++ Dev\ClientServeur\FolderMonitor.nca", @CRLF & "json in B:" & $CmdLine[1] & @CRLF)        
              Output:
                     
              lejson in A:{"DOSSIERS":{"Dossier_Hidden":"N:\\+++ Dev\\ClientServeur\\","Dossier_du_script":"N:\\+++ Dev\\ClientServeur\\","Fichier_Historique":"N:\\+++ Dev\\ClientServeur\\Historique.log","Fichier_DEBUG":"N:\\+++ Dev\\ClientServeur\\FolderMonitor.nca"}}
              json in B  :{DOSSIERS:{Dossier_Hidden:N:\\+++ Dev\\ClientServeur\\,Dossier_du_script:N:\\+++ Dev\\ClientServeur\\,Fichier_Historique:N:\\+++ Dev\\ClientServeur\\Historique.log,Fichier_DEBUG:N:\\+++ Dev\\ClientServeur\\FolderMonitor.nca}}
      As you see, i lost my quote in my json so it's au problem to parse my json.
      I use THIS library
      I tried different type of encoding (ex JSON_STRICT_PRINT), but i don't think that it's the problem. Maybe i'm wrong
       
      thanks
      Nicolas.
    • jandings
      By jandings
      Hello there,
      since I spent some time to access the REST-API of the web shop system Shopware, I'd like to share a few lines to make life easier for others.
      With this you can access your Shopware database, reading and writing all kind of data. 
      Replies are JSON style.
      To work with JSON I usually depend on either just own AutoIt string operations or this AutoIt library:
      ; File        : Json.au3 (2015.01.08)
      ; Purpose    : A Non-Strict JavaScript Object Notation (JSON) Parser UDF
      ; Author    : Ward
      $UserName="xxxx" ;Shopware credentials of Shopware user who has the API checkbox ticked $PassWord="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;API-Key of this user, NOT the Password $URL="www.XXX.com/api/" $Command="orders/64682?useNumberAsId=true" ;A list of commands and options is available through shopware REST-API help; Here we read order number 64682 $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") $oHTTP.Open("GET", "https://" & $URL & $Command , False) $oHTTP.SetCredentials($UserName, $PassWord, 0) $oHTTP.Send() $response = $oHTTP.ResponseText ConsoleWrite ($response & @CRLF & @CRLF)  
    • BJP
      By BJP
      Hello.  I have a program that has used ADO database connection to return a query and then subsequently put the query results into an array using getrows.  See snippet below:
      $constrim="DRIVER={SQL Server};SERVER=xxx-xxxxx\CSC;DATABASE=xxxxxxxxx;uid=xxxxxxxxxx;pwd=xxxxxxxxxxxx;" $adCN = ObjCreate ("ADODB.Connection") ; <== Create SQL connection $adCN.Open ($constrim) ; local $sQuery = "select * from tbl_Apps"                     ; get all applications in the database local $oAppRecordSet = $adCN.Execute($sQuery) local $aAppsInDB = $oAppRecordSet.Getrows(5000) With the code above I can perform array operations very efficiently. 
      Now I need to get this data via JSON which is working (using Ward's JSON UDF)  but the data set returned is large (approx 4MB) and I'm wondering what is the most efficient way to get this data into an array.  
      Dim $obj = ObjCreate ("WinHttp.WinHttpRequest.5.1") $obj.Open("GET", $URL, false) $obj.SetRequestHeader("Content-Type", "application/json") $obj.Send() $json = JSON_decode( $obj.ResponseText ) Any help would be appreciated!!
    • baolo073
      By baolo073
      [ [ [ "Kinh Oanh,\r\n", "Dear Oanh,\r\n", null, null, 3 ], [ "C\u1ea3m \u01a1n b\u1ea1n r\u1ea5t nhi\u1ec1u v졢\u1ee9c th\u01b0 c\u1ee7a b\u1ea1n \u0111\u1ebfn m\u1ed9t v᩠ngṠtr\u01b0\u1edbc. ", "Thank you very much for your letter which arrived a few days ago.", null, null, 3 ], [ "Th\u1eadt \u0111⯧ y뵠khi nghe t\u1eeb b\u1ea1n.\r\n", "It was lovely to hear from you.\r\n", null, null, 3 ], [ "b\u1ea1n \u0111i \u0111㵠v\u1eady.\r\n", "where do you go.\r\n", null, null, 1 ], [ "T\u1ea1m bi\u1ec7t!", "Goodbye!", null, null, 1 ] ], null, "en", null, null, null, 0.91366601, null, [ [ "en" ], null, [ 0.91366601 ], [ "en" ] ] ] How to parse array to json?
×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.