Nighter Posted February 27 Share Posted February 27 (edited) Hi all, I'm currently trying to read several information from a game api, in order to create a dashboard for myself with various information from for multiple accounts the api normally provides a json response, but sometimes the response is just an array (like for character names on that account), sometimes a json array with objects and sometimes a json object with other objects and arrays within these objects. In order to read the json response I stumbled over this UDF and used it to read the json data that came back from the api call (array of objects in this case). As I'm completely new to json etc I might have some logical misunderstandings. Now I wanted to create an array of objects on my own, based on the information I've retrieved and want to retrieve further, but somehow I'm stuck with the json_objcreate and json_objput. $dataresp=_INetGetSource($callurl) ;just the api URL, including the account token. It sends back a json response with an array of characternames of the account from the account-token $arrCharNames=Json_Decode($dataresp) local $character[UBound($arrCharNames)] for $i=0 to UBound($arrCharNames)-1 $character[$i]=Json_ObjCreate() json_objput($character[$i],".name",$arrCharNames[$i]) Json_Dump($character[$i]) next the array itselfs says each element is filled with an object (according to a test ) _ArrayDisplay($character[$i]) , but the Json_dump does not show anything in the console. My goal is to add several key-value pairs to each object of each $character[] element. I'm pretty sure I might misunderstood the json_xxx functions but unfortunately the functions are not documented pretty well in the UDF. maybe someone can point me into the right direction Edited March 6 by Jos Link to comment Share on other sites More sharing options...
Developers Jos Posted February 27 Developers Share Posted February 27 Welcome to the AutoIt forum. Unfortunately you appear to have missed the Forum rules on your way in. Please read them now - particularly the bit about not discussing game automation - and then you will understand why you will get no help and this thread will now be locked. See you soon with a legitimate question I hope. The Moderation team 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 March 6 Developers Share Posted March 6 I have unlocked this thread and will allow it as it is using a standard api not using for automation according the OP. SOLVE-SMART 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...
Nine Posted March 6 Share Posted March 6 Since we do not have access to the API, provide the _INetGetSource string you get. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Nighter Posted March 6 Author Share Posted March 6 I'm still thinking I might misunderstood json overall .. I've "created" a Json file on my own now. the code below is just a short example the overall array under the gw2 object counts 60 entries (some filled with objects like shown, some just empty), The objects characters, wallet and inventory should be filled later on with information read from the api { "gw2": [ { }, { "acc": "accountname", "email": "accountmail", "apitoken":"apitoken", "characters":{ }, "wallet":{ }, "inventory":{ } }, ] } if I read that file now $obj=json_decode(FileRead("pathtojsonfile")) and try to dump it with json_dump($obj) nothing is shown in the console, but I thought that I should get the information that there is a json object ".gw2" I can show the array with _ArrayDisplay(json_get($obj,".gw2")) but how do I get all the key/value pairs from each array item? Link to comment Share on other sites More sharing options...
paw Posted March 6 Share Posted March 6 your json is invalid Quote { "gw2": [ {}, { "acc": "accountname", "email": "accountmail", "apitoken": "apitoken", "characters": {}, "wallet": {}, "inventory": {} } ] } Link to comment Share on other sites More sharing options...
Nighter Posted March 6 Author Share Posted March 6 16 minutes ago, paw said: your json is invalid why is it invalid? the first item of the array in the object "gw2" is just empty .. same for characters, wallet and inventory .. all of these contains empty objects .. Link to comment Share on other sites More sharing options...
Developers Jos Posted March 6 Developers Share Posted March 6 Did you try removing that extra comma : }, ] } like: } ] } ? 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...
Nine Posted March 6 Share Posted March 6 You know basically json UDF is just regex driven. Make your own regex to perform what you want, and forget about the UDF. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy 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