Jump to content

some questions regarding json interaction


Recommended Posts

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 by Jos
Link to comment
Share on other sites

  • Developers

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

  • Jos unlocked this topic
  • Developers

I have unlocked this thread and will allow it as it is using a standard api not using for automation according the OP.

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

  • Jos changed the title to some questions regarding json interaction

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

your json is invalid

Quote

{
    "gw2": [
        {},
        {
            "acc": "accountname",
            "email": "accountmail",
            "apitoken": "apitoken",
            "characters": {},
            "wallet": {},
            "inventory": {}
        }
    ]
}

 

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...