Jump to content

Recommended Posts

Posted

Hello,

I can't get a specific  data from a json file. I use json.au3  from WArd (JSMN) 

I want to get the values between [ ..] in  vehicule: ["velo", "voiture","poids_lourd"],

see attached file for more details

I tried : $vehicule= json_get($object, '[' & $i & '].vehicule') **it's in a loop**

-> result is always "" empty

i tried   $vehicule= json_objget($object, '[' & $i & '].vehicule')

             $vehicule[0]= json_objget($object, '[' & $i & '].vehicule')

-> error in json.au3 about bad $object variable

i tried plenty other stupid things changing syntax : no way...

thank you for your help 

 

 

exemple.json

  • Moderators
Posted

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

@butathermix

The json_dump() function may help you understand the correct syntax for accessing items within an json array object.

 

Given the snippet below, using your VERY terse example, you will get the following result:

#include <MyIncludes\json\json.au3>

Global $sJson = '{vehicule: ["velo", "voiture","poids_lourd"]}'
ConsoleWrite('JSON Dump' & @CRLF)
Json_Dump($sJson)

Global $oJson = Json_Decode($sJson)
ConsoleWrite(@CRLF)
ConsoleWrite('Sample display of JSON array items' & @CRLF)
ConsoleWrite('vehicule[0] = ' & Json_Get($oJson, '.vehicule[0]') & @CRLF)
ConsoleWrite('vehicule[1] = ' & Json_Get($oJson, '.vehicule[1]') & @CRLF)
ConsoleWrite('vehicule[2] = ' & Json_Get($oJson, '.vehicule[2]') & @CRLF)

Will give you a result of:

JSON Dump
+=> .vehicule[0]=>velo
+=> .vehicule[1]=>voiture
+=> .vehicule[2]=>poids_lourd

Sample display of JSON array items
vehicule[0] = velo
vehicule[1] = voiture
vehicule[2] = poids_lourd

 

It appears that you were putting the index BEFORE the object's name.  As you can see from the dumping of the JSON, that syntax is backwards.

 

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
×
×
  • Create New...