butathermix Posted July 25, 2018 Posted July 25, 2018 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 JLogan3o13 Posted July 25, 2018 Moderators Posted July 25, 2018 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!
TheXman Posted July 25, 2018 Posted July 25, 2018 @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. CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
butathermix Posted July 26, 2018 Author Posted July 26, 2018 hello Thexman , thank you a lot it works fine ! it was so simple that i feel ashamed not to have find alone ! Thank you again and good day !!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now