Jump to content
Ward

A Non-Strict JSON UDF (JSMN)

Recommended Posts

dexto

Implementation of the JSMN using Map available in Autoit Beta (3.3.15):

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****


#include "jsonMap.au3"

$json = '{"test":"yay"}'
$test = Json_Decode($json)
ConsoleWrite($test['test'] & @CRLF)

$test['test'] = 'horray!!!'
ConsoleWrite($test['test'] & @CRLF)

ConsoleWrite(Json_Encode($test) & @CRLF)

 

 

jsonMap.au3

Edited by dexto
Fixed a bug in the Json_Encode_Pretty()
  • Like 2

Share this post


Link to post
Share on other sites
argumentum
31 minutes ago, dexto said:

Implementation of the JSMN using Map

so, what is the use of the addition of

Local $default[]
If $json = "" Then Return SetError(0, 1, $default)

Edit: ok, got it.

Edited by argumentum

Share this post


Link to post
Share on other sites
satanico64

Edit of my answer on the importance of simple and double quote.

Quote

$akeys = Json_ObjGetKeys($JsoEqpt)

    Json_Get($JsoEqpt, '["' & $akeys[0] & '"]["tagInge"]')        => OK  Key between Double quotes:   '   [   "   '   & $akeys
    Json_Get($JsoEqpt, '["' & $akeys[0] & "']['tagInge']")        => Not OK, key between simple quotes    "   [   '   "   & $akeys

    I must indicate that my keys are Numbers only overwise i think it's ok with string key!

 

 

 

 

Share this post


Link to post
Share on other sites
satanico64

hi guys !!! how are you ? fine ? nice !!!

does anyone has encountered problems, using several Json ?

I encounter a problem, i just can't success in creating a simple example to show you but i can show you a part of it :'(

Context: in my code i use 2 json, the final one, and the other is for temporary use, (in a loop and clear).

The deal is to create an array of object and add it to my json. It's ok but an array is modified when i modifiy the other... i'm going crazy...:mad:

 

I m gonna show you state of my 2 json, a jsonclear of the first one, and the second is affected too..(it change !)

 

Sorry again not giving usable example... but maybe this will gave you ideas...

Problem just with adding something to a json, the other is affected.

ConsoleWrite("Just any text to show you this is the good part of the code..." & @crlf)
                            ConsoleWrite("$JsonPopupEqpt:" & json_encode($JsonPopupEqpt) & @CRLF)
                            ConsoleWrite("$Jsontemporaire:" & json_encode($Jsontemporaire) & @CRLF)
                            ConsoleWrite("$aema:" & $aema & @CRLF )
                            ConsoleWrite("$letexte:" & $letexte & @CRLF )
                            Json_Put($Jsontemporaire, '["AEMA"]', $aema)
                            Json_Put($Jsontemporaire, '["NumeroSerie"]', $letexte)
                            ConsoleWrite("has Json_Popup_Eqpt change ?:" &json_encode($JsonPopupEqpt) & @CRLF  )
                            ConsoleWrite("Just any text  blablabla" & @crlf)

Console output:

Spoiler

Just any text to show you this is the good part of the code...
$JsonPopupEqpt:{"ListeAEMA_NS_Depose":[],"ListeAEMA":"","ListeNS":"","ListeAEMA_NS_Reprise":[{"AEMA":"AEMARAD00040","NumeroSerie":"1625004894"}],"Mouvement":"Remplacement"}
$Jsontemporaire:{"AEMA":"AEMARAD00040","NumeroSerie":"1625004894"}
$aema:AEMANBE00200
$letexte:F207420006029
has Json_Popup_Eqpt change ?:{"ListeAEMA_NS_Depose":[],"ListeAEMA":"","ListeNS":"","ListeAEMA_NS_Reprise":[{"AEMA":"AEMANBE00200","NumeroSerie":"F207420006029"}],"Mouvement":"Remplacement"}
Just any text  blablabla

 

Please note that the JsonPopupEqpt is not the same, i just don't touch it.

 

Problem just with an Objclear the other json is affected.

ConsoleWrite("Just any text to show you this is the good part of the code..." & @crlf)
                            ConsoleWrite("$JsonPopupEqpt:" & json_encode($JsonPopupEqpt) & @CRLF)
                            ConsoleWrite("$Jsontemporaire:" & json_encode($Jsontemporaire) & @CRLF)
                            ConsoleWrite("$aema:" & $aema & @CRLF )
                            ConsoleWrite("$letexte:" & $letexte & @CRLF )
                            Json_ObjClear($Jsontemporaire)
                            ConsoleWrite("has Json_Popup_Eqpt change ?:" &json_encode($JsonPopupEqpt) & @CRLF  )
                            ConsoleWrite("$Jsontemporaire:" & json_encode($Jsontemporaire) & @CRLF)
                            ConsoleWrite("Just any text  blablabla" & @crlf)

 

Console output:

Spoiler

Just any text to show you this is the good part of the code...
$JsonPopupEqpt:{"ListeAEMA_NS_Depose":[],"ListeAEMA":"","ListeNS":"","ListeAEMA_NS_Reprise":[{"AEMA":"AEMARAD00040","NumeroSerie":"1625004894"}],"Mouvement":"Remplacement"}
$Jsontemporaire:{"AEMA":"AEMARAD00040","NumeroSerie":"1625004894"}
$aema:AEMANBE00200
$letexte:F207420006029
has Json_Popup_Eqpt change ?:{"ListeAEMA_NS_Depose":[],"ListeAEMA":"","ListeNS":"","ListeAEMA_NS_Reprise":[{}],"Mouvement":"Remplacement"}
$Jsontemporaire:{}
Just any text  blablabla

Note that my json JsonPopupEqpt has it field ListeAEMA_NS_Reprise reset.... d'ont know why

They are all created with

local $JsonPopupEqpt
    If Json_IsObject($JsonPopupEqpt) Then
        Json_ObjClear($JsonPopupEqpt)
    Else
        $JsonPopupEqpt = Json_ObjCreate()
    EndIf

I've tried, renaming the jsons, (in case there are the same name is the udf), i removed the initial '_' in the name...

I'm running out of ideas...

 

I give you poor information, and no example to test, i'm sorry for that... i can't reproduce in a standalone program.

So i just ask for ideas... thanks for your comprehension

Nicolas.

Edited by satanico64
correct errors

Share this post


Link to post
Share on other sites
Inververs

It look like you try to modify a object. All objects modificatian are doing byref.

Share this post


Link to post
Share on other sites
satanico64

hi, and thanks for your answer, everything help :)

 

For sure i modify an object, it's what i want.

The 2 objects i show in my example are different ( but with same fields/type ) but i modify the first ,one the second is modified too...

I thing there is something wrong with the format. I got the problem if i modify the object, and even if i clear the object.

 

Format of my json is: { Array1 [ object, object, object...] , Array2 [ object, object, object...] }

I thing something goes wrong using array of objects, or maybe the fact i had initialised an empty array in my json

 

Indeed, i just bypass the problem using notation and only one Json::)

i just erased all, and totally rewrite...

something like:

local $JsonPopupEqpt
    If Json_IsObject($JsonPopupEqpt) Then
        Json_ObjClear($JsonPopupEqpt)
    Else
        $JsonPopupEqpt = Json_ObjCreate()
    EndIf

    Json_Put($JsonPopupEqpt, ".ListeAEMA_NS_Reprise[0].AEMA", $aema)
    Json_Put($JsonPopupEqpt, ".ListeAEMA_NS_Reprise[0].NumeroSerie", $ns)    
    Json_Put($JsonPopupEqpt, ".ListeNS", $ListeNS)
    
    ; my loop has disappear and is replaced now by: 
     $i = UBound(Json_Get($JsonPopupEqpt,".ListeAEMA_NS_Depose") )
        Json_Put($JsonPopupEqpt, ".ListeAEMA_NS_Depose[" & $i & "].AEMA", $aema)
        Json_Put($JsonPopupEqpt, ".ListeAEMA_NS_Depose[" & $i & "].NumeroSerie", $letexte)

code shorter, cleaner and it works.

Do you know any tip to get array size in the json ?

i use  $i = UBound(Json_Get($JsonPopupEqpt,".ListeAEMA_NS_Depose") )  , it works but maybe there's a different way...

 

Thanks

Nicolas

Share this post


Link to post
Share on other sites
MimiOne

Hi Ward

The keys of type "integer" or of type "string" are allowed in Map variable (Autoit) (as well as in scripting dictionary), and are not the same.
The Json encoding results in a change of type of keys, type "integer".
Example:

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

ConsoleWrite("======================== MAP ===========================" & @CRLF)
;-- Tableau 2D à include dans la Map --
    Global $aTest1[2] = ['ROUGE', 'VIOLET']

    Global $Map[], $MapOut
    $Map["Cle1"] = "DataCle1"
    $Map["Cle2"] = "DataCle2"
    $Map["2"] = "DataCleString"
    $Map[2] = "DataCleNum"
    $Map["Cle3"] = $aTest1

    Global $code = Json_Encode($Map)
    ConsoleWrite('Map     Code: ' & $code & @CRLF)

    $MapOut = Json_Decode($code)

    ;-- Affichages -------------------------------
    Global $aKeys = MapKeys ($MapOut)
;~  _ArrayDisplay ($aKeys)
    ConsoleWrite("Type Cle1 = " & VarGetType($aKeys[0]) & @CRLF)
    ConsoleWrite("Type Cle2 = " & VarGetType($aKeys[1]) & @CRLF)
    ConsoleWrite('Type "2" = ' & VarGetType($aKeys["2"]) & @CRLF)
    ConsoleWrite("Type 2 = " & VarGetType($aKeys[2]) & @CRLF)

    ConsoleWrite("$MapOut[Cle1]= " & $MapOut["Cle1"] & @CRLF)
    ConsoleWrite("$MapOut[Cle2]= " & $MapOut["Cle2"] & @CRLF)
    ConsoleWrite('$MapOut["2"]= ' & $MapOut["2"] & @CRLF)
    ConsoleWrite("$MapOut[2]= " & $MapOut[2] & @CRLF)
;~  _ArrayDisplay($MapOut["Cle3"])

    ;-- Nouveau codage du résultat ----------
    Global $codeOut = Json_Encode($MapOut)
    ConsoleWrite('MapOut     Code: ' & $codeOut & @CRLF)

    ;-- comparaison des codes ---------------
    If $codeOut = $code Then
        ConsoleWrite("$codeOut = $code" & @CRLF)
    Else
        ConsoleWrite("$codeOut <> $code" & @CRLF)
    EndIf

result:

Spoiler

======================== MAP ===========================
Map     Code: {"Cle1":"DataCle1","Cle2":"DataCle2","2":"DataCleString","2":"DataCleNum","Cle3":["ROUGE","VIOLET"]}
Type Cle1 = String
Type Cle2 = String
Type "2" = String
Type 2 = String
$MapOut[Cle1]= DataCle1
$MapOut[Cle2]= DataCle2
$MapOut["2"]= DataCleNum
$MapOut[2]=
MapOut     Code: {"Cle1":"DataCle1","Cle2":"DataCle2","2":"DataCleNum","Cle3":["ROUGE","VIOLET"]}
$codeOut <> $code

Kind regards.

Edited by MimiOne

Share this post


Link to post
Share on other sites
AMSPeople

Hi. I can not get value of 'dst' attr from JSON:

{"trans_result":{"from":"en","to":"zh","domain":"all","type":2,"status":0,"data":[{"dst":"\u6d4b\u8bd5","src":"test","relation":[],"result":[[0,"\u6d4b\u8bd5",["0|4"],[],["0|4"],["0|6"]]]}],"phonetic":[{"src_str":"\u6d4b","trg_str":"c\u00e8"},{"src_str":"\u8bd5","trg_str":"sh\u00ec"}]}}

This is table:

$aJSON['trans_result']['data']

But

$aJSON['trans_result']['data'][0]

gives an error message: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

 

Share this post


Link to post
Share on other sites
AMSPeople

My func:

Func _URIEncode($sData)
    Local $aData = StringSplit(BinaryToString(StringToBinary($sData, 4), 1), "")
    Local $nChar
    $sData = ""
    For $i = 1 To $aData[0]
        $nChar = Asc($aData[$i])
        Switch $nChar
            Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126
                $sData &= $aData[$i]
            Case 32
                $sData &= "+"
            Case Else
                $sData &= "%" & Hex($nChar, 2)
        EndSwitch
    Next
    Return $sData
EndFunc   ;==>_URIEncode
Func _GetTranslateBaidu($sText)
    Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("Post", "http://translate.baidu.com/v2transapi", False)
    $oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
    $oHTTP.SetRequestHeader("Host", 'translate.baidu.com')
    $oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")
    $oHTTP.SetRequestHeader("Connection", "keep-alive")

    ConsoleWrite('from=en&to=zh&query=' & _URIEncode($sText) & '&transtype=translang&simple_means_flag=3' & @CRLF)

    $oHTTP.Send('from=en&to=zh&query=' & _URIEncode($sText) & '&transtype=translang&simple_means_flag=3')
    If ($oHTTP.Status == 200) Then
        $sJSON = $oHTTP.ResponseText
        $aJSON = Json_Decode($sJSON, 10000)
        ConsoleWrite($aJSON['trans_result']['data'][0]['dst'] & @CRLF)
    EndIf
EndFunc   ;==>_GetTranslateBaidu

Include: jsonMap.au3

Edited by AMSPeople
  • Like 1

Share this post


Link to post
Share on other sites
Danyfirex

You can do this:

Local $oJson = Json_Decode($sJson)
Local $dst=Json_Get($oJson,'["trans_result"]["data"][0]["dst"]')

Saludos

Share this post


Link to post
Share on other sites
AMSPeople

 

 error: Json_Get(): undefined function.

I use jsonMap:

Udf from the first post can not be downloaded.

I found in another location JSON.au3 library from ward.

There was another question. Can I somehow know the number of elements inside the element ["trans_result"] ["data"]?
Since variants are possible ["trans_result"] ["data"] [0] ["dst"], ["trans_result"] ["data"] [1] ["dst"], ["trans_result"] ["data "] [2] [" dst "] and so on.

 

$oJSON = Json_Decode($sJSON)
        Local $aLines = Json_Get($oJSON, '["trans_result"]["data"]')
        For $i = 0 To UBound($aLines) - 1
            $sDst = Json_Get($oJSON, '["trans_result"]["data"][' & $i & ']["dst"]')

            MsgBox(0, '', $sDst)
            ConsoleWrite($sDst & @CRLF)
        Next

 

Edited by AMSPeople

Share this post


Link to post
Share on other sites
Taz77
13 hours ago, AMSPeople said:

Hi. I can not get value of 'dst' attr from JSON:

{"trans_result":{"from":"en","to":"zh","domain":"all","type":2,"status":0,"data":[{"dst":"\u6d4b\u8bd5","src":"test","relation":[],"result":[[0,"\u6d4b\u8bd5",["0|4"],[],["0|4"],["0|6"]]]}],"phonetic":[{"src_str":"\u6d4b","trg_str":"c\u00e8"},{"src_str":"\u8bd5","trg_str":"sh\u00ec"}]}}

This is table:

$aJSON['trans_result']['data']

But

$aJSON['trans_result']['data'][0]

gives an error message: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

 

 

 

So it is also easy with jsonMap :)

Global $sString = '{"trans_result":{"from":"en","to":"zh","domain":"all","type":2,"status":0,"data":[{"dst":"\u6d4b\u8bd5","src":"test","relation":[],"result":[[0,"\u6d4b\u8bd5",["0|4"],[],["0|4"],["0|6"]]]}],"phonetic":[{"src_str":"\u6d4b","trg_str":"c\u00e8"},{"src_str":"\u8bd5","trg_str":"sh\u00ec"}]}}'
Global $mMap = Json_Decode($sString)
Global $aArray = $mMap.trans_result.data
Global $mData = $aArray[0]

ConsoleWrite($mData.dst & @CRLF)

 

Edited by Taz77

Share this post


Link to post
Share on other sites
nhardel

Download links seem to be dead.   Where might I get this UDF and all supporting files?

Share this post


Link to post
Share on other sites
Decibel

How do you get a count of elements within an array? Json_ObjGetCount doesn't seem to be it.

#Include "JSon.au3"

Local $Json = '{"name":"John","cars":[ "Ford", "BMW", "Fiat", "Chevy" ]}'

;Correctly returns a count of 2 elements (name and cars)
Local $Obj = JSon_Decode($Json)
ConsoleWrite("count root: " & Json_ObjGetCount($Obj) & @CRLF) 

;Returns error Variable must be of type "Object"
Local $Cars = Json_ObjGet($Obj, '["cars"][0]')
ConsoleWrite("count cars: " & Json_ObjGetCount($aCars) & @CRLF)

Or is the only way to first loop through the array and make my own counter, then go back through and reference what I want to do?

Share this post


Link to post
Share on other sites
TheDcoder

@Decibel Use Ubound($aCars) to get count of an array.

  • Like 1

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
Decibel
On 10/12/2017 at 11:15 PM, TheDcoder said:

@Decibel Use Ubound($aCars) to get count of an array.

Thanks. I didn't realize that the JSON Arrays were "just arrays." Solution provided below for others.

#Include "JSon.au3"
    
    Local $Json = '{"name":"John","cars":[ "Ford", "BMW", "Fiat", "Chevy" ]}'

    ;Correctly returns a count of 2 elements (name and cars)
    Local $Obj = JSon_Decode($Json)
    ConsoleWrite("count root: " & Json_ObjGetCount($Obj) & @CRLF)

    ;Returns error Variable must be of type "Object"
    ;Local $Cars = Json_ObjGet($Obj, '["cars"][0]')
    ;ConsoleWrite("count cars: " & Json_ObjGetCount($aCars) & @CRLF)

    ;Solution from TheDcoder
    Local $aCars = Json_Get($Obj, '["cars"]')
    ConsoleWrite("count cars: " & UBound($aCars) & @CRLF)
    
    ;Walking the array
    For $iCurrentCar = 0 To UBound($aCars) - 1 ;zero-based array
        ConsoleWrite("Car '" & $iCurrentCar & "' of '" & UBound($aCars) & "' is '" & _
            Json_Get($Obj, '["cars"][' & $iCurrentCar & ']') & "'" & @CRLF)
    Next

 

  • Like 3

Share this post


Link to post
Share on other sites
TheDcoder

The UDF converts them into native data-types before returning them :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
Danp2

Is there a better way to retrieve this value?

Local $sJSON = '{"value":{"element-6066-11e4-a52e-4f735466cecf":"638265bf-bd34-4ea4-8605-b719c9c98538"}}'
Local $Obj = Json_Decode($sJSON)
Local $Obj2 = Json_Get($Obj, "[value]")
Local $sResult = Json_ObjGetKeys($Obj2)[0]
ConsoleWrite($sResult & @CRLF)

 

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

    • Skysnake
      By Skysnake
      I know how JSON works. However JSON data is typically received from web based servers. 
       
      My question is:
      Has anyone considered to use, or currently actively using JSON as an internal data container? 
      Internal here as in an ordinary AutoIt data type, generated, populated and manipulated within an AutoIt script, without any external data sources. 
      The JSON and BinaryCall UDFs work well and appear the de facto defaults. Are there any thoughts on using JSON for internal variable values instead of the typical array? 
      Also, there can be situations where such a JSON collection contains an array and it will have to be parsed using typical array functions. 
      Currently I am working on a small project where I have to keep and use various identifiers from different sources. There are several ideas in this regard, some involving SQL child tables and arrays stored with keys (maps), which lead me to think that JSON may be a more suitable data container. It readily shrinks and stretches, allowing for dynamic data growth.  JSONs ability to add new repeating data groups on the fly makes it particularly powerful and appealing. 
      Ideas and suggestions welcome
      Skysnake
    • jantograaf
      By jantograaf
      Hi all,
      I'm trying to create a script that runs a JSON-query and then can retrieve some variables out of the returned, decoded object using JSON.au3. I have tried some other examples on this forum, but I'm stuck at one point. My query works perfectly and gets loaded into the variable $data. Then, decoding $data to $object seems to work as well. But then I can't get the date-field out of this JSON-structure with my script.
      The JSON-structure returned looks like this:
      { "content": [ { "id": "451ec583-8f27-4926-82a3-a2d85e57a110", "createdDate": "2018-08-08T08:40:57.449004Z", "updatedDate": "2018-08-08T08:40:57.449004Z", "lastOpenedDate": "2018-08-08T08:40:57.449004Z", "date": "2018-04-26T00:00:00", "description": "X-Ray Exam", "patient": { "id": "f857238a-c75d-4760-b8d1-8f50f8f9bbfa", "createdDate": "2018-08-08T08:40:37.623976Z", "updatedDate": "2018-08-08T08:40:37.623976Z", "lastOpenedDate": "2018-08-08T08:40:37.623976Z", "name": "Fuerstonia", "birthDate": "2014-06-08", "breed": "", "chip": "", "color": "", "damsire": "", "sire": "", "neutered": false, "orthancUuid": "", "sex": "U", "species": "Paard", "ueln": "De 431310762114", "pmsReference": "", "origin": "" }, "type": "study", "accessionNumber": "KME201806960467", "instanceUid": null, "orthancUuid": "", "sent": false, "seriesCount": 0, "modalityType": "RX", "typeAndModality": "study RX", "client": { "id": "be627195-8458-4927-8446-f1ef37b917a4", "createdDate": "2018-08-08T08:40:31.433968Z", "updatedDate": "2018-08-08T08:40:31.433968Z", "lastOpenedDate": "2018-08-08T09:26:49.512298Z", "via": "", "extraInfo": "", "pmsReference": "", "contact": { "id": "406cc555-c491-4c29-b6bb-8d903f0e35a9", "createdDate": "2018-08-08T08:40:31.428968Z", "updatedDate": "2018-08-08T08:40:31.428968Z", "lastName": "Client 1", "firstName": "", "company": "", "email": "", "language": "nl", "phone": "", "address": { "id": "6fc7703c-137a-4e0a-ba96-8c7f38f2044b", "city": "", "country": "", "line": "", "postalCode": "" } } } }, My script looks like this:
      #RequireAdmin #include <json.au3> #include <inet.au3> #include <File.au3> ;Create a handle to a logfile (will be created if it doesnt exist) Global $logfile = FileOpen("C:\VSOL\VSTK\Logs\MigrationFix\MigrationFix.log",9) FileWriteLine($logfile,"Start script") ;Create the URL with the JSON-query $URL = "http://localhost:8080/v0/studies/?seriesCount=1" ;Catch the query output into a variable $data = _INetGetSource($URL) ;Check if there is any data at all in this variable, if not, exit If Not $data Then MsgBox(1,"Error","No answer. Server is probably not running.") Exit EndIf ;For debugging purposes FileWriteLine($logfile,$data) ;Decode the JSON_string into a useable object $object = Json_Decode($data,1000) If @error Then FileWriteLine($logfile,"Error decoding JSON") Exit EndIf Local $i = 0 ;Start a loop to retrieve the study date of each study... While 1 $study_date = json_get($object,'[' & $i & '].date') If @error Then FileWriteLine($logfile,"Study-Date retrieval error") ExitLoop EndIf $i = $i + 1 WEnd ;Close the logfile FileWriteLine($logfile,"Stop script") FileClose($logfile) ;Open the logfile for quick reference ShellExecute("C:\VSOL\VSTK\Logs\MigrationFix\MigrationFix.log") If believe it has something to do with my json_get($object...)-command. Anyone who can point me in the right direction?
      Thanks in advance!
      Kind regards
    • 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)  
×