Danp2 Posted January 9, 2018 Share Posted January 9, 2018 Actually, that's retrieving the key when I really it's value. Here's my latest rendition -- 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 $sKey = Json_ObjGetKeys($Obj2)[0] Local $sResult = Json_Get($Obj, "[value][" & $sKey & "]") ConsoleWrite($sResult & @CRLF) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Developers Jos Posted January 13, 2018 Developers Share Posted January 13, 2018 Added JsonDump() and updated/attached a new Zipfile in first post Jos Danp2, Xandy and TheDcoder 3 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted January 20, 2018 Developers Share Posted January 20, 2018 (edited) Show an script that you are testing with so we can see what you are doing. 10 minutes ago, TiC01 said: And I don't want these "" ..... Don't know what you mean by that comment. Jos Edited January 20, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
TheDcoder Posted January 20, 2018 Share Posted January 20, 2018 21 minutes ago, TiC01 said: Local $array[1] = [] Make that: Local $aArray[0] EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
TheDcoder Posted January 20, 2018 Share Posted January 20, 2018 (edited) No problem, $aArray[0] creates an empty array, you were using $aArray[1] which was creating an array with a single element/row, by default all variables are strings so that one element translated into an empty string, this is why you were seeing a single "" in the outputted JSON Edited January 20, 2018 by TheDcoder TiC01 and Xandy 2 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
x_bennY Posted February 7, 2018 Share Posted February 7, 2018 (edited) How do i get the object count? When i try to do it i receive this error: : ==> Variable must be of type "Object".: Return $Object.Count Return $Object^ ERROR $data = fileread("test.json") $object = json_decode($data) Edited February 7, 2018 by x_bennY Link to comment Share on other sites More sharing options...
Developers Jos Posted February 7, 2018 Developers Share Posted February 7, 2018 You aren't providing the "test.json" input file, so can only guess that the json_decode($data) doesn't return an object but rather an @error, for which you aren't checking. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
x_bennY Posted February 8, 2018 Share Posted February 8, 2018 @Jos Hey, sorry, i forgot to post it! expandcollapse popup[ { "IDPredio":9, "DSPredio":"Anfi Teatro", "DSLocalizacao":"No prédio de direito", "DSCursos":"Vários", "NOImagem":"anfiteatro.jpg", "NRSalasPredio":null }, { "IDPredio":16, "DSPredio":"Business Andar Superior", "DSLocalizacao":"Shopping Boulevard", "DSCursos":"Varios", "NOImagem":"boulevard.jpg", "NRSalasPredio":7 }, { "IDPredio":13, "DSPredio":"Business Terreo", "DSLocalizacao":"Shopping Boulevard", "DSCursos":"Varios", "NOImagem":"boulevard_terreo.jpg", "NRSalasPredio":8 }, { "IDPredio":8, "DSPredio":"Cine Teatro", "DSLocalizacao":"Próximo ao prédio tecnológico", "DSCursos":"Vários", "NOImagem":"cineteatro.jpg", "NRSalasPredio":null }, { "IDPredio":5, "DSPredio":"Prédio Biomédicas", "DSLocalizacao":"Próximo ao Centro de Vivências", "DSCursos":"Vários", "NOImagem":"biomedicas.jpg", "NRSalasPredio":41 }, { "IDPredio":4, "DSPredio":"Prédio Humanas", "DSLocalizacao":"Próximo a entrada principal", "DSCursos":"Direito, Artes Cênicas", "NOImagem":"humanas.jpg", "NRSalasPredio":32 }, { "IDPredio":6, "DSPredio":"Prédio Inotec", "DSLocalizacao":"Próximo a biblioteca", "DSCursos":"Vários", "NOImagem":"inotec.jpg", "NRSalasPredio":23 }, { "IDPredio":2, "DSPredio":"Prédio Tecnológico", "DSLocalizacao":"Próximo ao Cineteatro", "DSCursos":"Ciência da Computação, Sistemas de Informação", "NOImagem":"tecnologico.jpg", "NRSalasPredio":36 }, { "IDPredio":17, "DSPredio":"Sequenciais", "DSLocalizacao":"Mesmo predio da biblioteca", "DSCursos":"vários", "NOImagem":"inotec.jpg", "NRSalasPredio":6 } ] Link to comment Share on other sites More sharing options...
hmobron Posted February 8, 2018 Share Posted February 8, 2018 (edited) Hello thanks for the great UDF. Can you please explain how to access non root values? Root value like .firstname = Willem Cornelis i can access by using Json_ObjGet( $json2, "firstname") From Json_Dump .families[0].spouse.lastname = Engel .mother.sosa =2 I running Autoit script 3.3.14.3 with Json(2018.01.13).zip note json.au3 in the head says ; File : Json.au3 (2015.01.08) Edited February 8, 2018 by hmobron Link to comment Share on other sites More sharing options...
Developers Jos Posted February 8, 2018 Developers Share Posted February 8, 2018 14 hours ago, x_bennY said: sorry, i forgot to post it! Thanks, that helps. So the returned information is not an object so that is why you get that error. What are you exactly after in terms of a count for this json data? Jos x_bennY 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 8, 2018 Developers Share Posted February 8, 2018 4 hours ago, hmobron said: Hello thanks for the great UDF. Can you please explain how to access non root values? Root value like .firstname = Willem Cornelis i can access by using Json_ObjGet( $json2, "firstname") From Json_Dump .families[0].spouse.lastname = Engel .mother.sosa =2 I running Autoit script 3.3.14.3 with Json(2018.01.13).zip note json.au3 in the head says ; File : Json.au3 (2015.01.08) I don't understand the question as the json_dump UDF I wrote should tell you exactly what the keys is for a specific field. It helps when you post some example code, define what you expect and what is going wrong. Jos x_bennY 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
x_bennY Posted February 8, 2018 Share Posted February 8, 2018 1 hour ago, Jos said: Thanks, that helps. So the returned information is not an object so that is why you get that error. What are you exactly after in terms of a count for this json data? Jos I just want to know how many sections that json have... in that case it has 9 Link to comment Share on other sites More sharing options...
Developers Jos Posted February 8, 2018 Developers Share Posted February 8, 2018 (edited) You could use this logic and turn that into a Func: #include <json.au3> Global $data = FileRead("test.json") Global $object = json_decode($data) Global $i = 0 While 1 $product_id = json_get($object, '[' & $i & ']') If @error Then ExitLoop $i += 1 WEnd ConsoleWrite('Number of records:' & $i & @CRLF) Jos Edited February 8, 2018 by Jos Cut&Paste error x_bennY 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
hmobron Posted February 8, 2018 Share Posted February 8, 2018 4 hours ago, Jos said: I don't understand the question as the json_dump UDF I wrote should tell you exactly what the keys is for a specific field. It helps when you post some example code, define what you expect and what is going wrong. Jos O there is nothing wrong with the code. I am wrong I don't understand how to get the values from the keys. This from the dump .mother.sosa =2 . Json_ObjGet( $json2, 'mother=>sosa') = '' Json_ObjGet( $json2, "['mother']['sosa']") = '' Json_ObjGet( $json2, ".mother.sosa") = '' Json_ObjGet( $json2, "\mother\sosa") = '' and so on. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 8, 2018 Developers Share Posted February 8, 2018 (edited) As simple as: Json_ObjGet( $json2, ".mother.sosa")... but again... post a code snippet with the test data so I can see what is happening. Jos Edited February 8, 2018 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
hmobron Posted February 9, 2018 Share Posted February 9, 2018 (edited) 8 hours ago, Jos said: As simple as: Json_ObjGet( $json2, ".mother.sosa")... but again... post a code snippet with the test data so I can see what is happening. Jos Sorry, tested that to. Local $hFileOpen = FileOpen('json.txt') Local $sFileRead = FileRead($hFileOpen) FileClose($hFileOpen) $json2 = Json_Decode($sFileRead) if @error then MsgBox(0,'',@error) ConsoleWrite('output1: ' & Json_ObjGet( $json2, '.mother.sosa') & @LF ) ConsoleWrite('output: ' & Json_ObjGet( $json2, "lastname") & @LF ) Json_Dump($sFileRead) At the console: output1: output: Mobron The json file is large, so i uploaded to my domain: https://mobron.nl/wp-content/uploads/2018/02/json.txt It is a output from a web api. Edited February 9, 2018 by hmobron Link to comment Share on other sites More sharing options...
Developers Jos Posted February 9, 2018 Developers Share Posted February 9, 2018 I guess that should be: ConsoleWrite('output1: ' & Json_Get( $json2, '.mother.sosa') & @LF ) ConsoleWrite('output: ' & Json_Get( $json2, ".lastname") & @LF ) Jos JSON blijft lastig SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
hmobron Posted February 10, 2018 Share Posted February 10, 2018 19 hours ago, Jos said: I guess that should be: ConsoleWrite('output1: ' & Json_Get( $json2, '.mother.sosa') & @LF ) ConsoleWrite('output: ' & Json_Get( $json2, ".lastname") & @LF ) Jos JSON blijft lastig That worked, sorry that i missed that. But what is the dividends between those functions Json_Get and Json_ObjGet? Link to comment Share on other sites More sharing options...
x_bennY Posted March 9, 2018 Share Posted March 9, 2018 @Jos Now i'm using the Packege UDF to store some txt files and read it, it's around 2 thousand files... to read one of the data it takes around 2secs. If i change it to json, it will be faster? I'm trying to create a database and i don't know what is the best option. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 9, 2018 Developers Share Posted March 9, 2018 I have no idea as your provided scenario is very explicit. It probably all depends what kind of lexing you need to do with those text files when reading processing them. Just give it a try and simply test it would be the best advice as that will give you a conclusive answer. Jos x_bennY 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
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