Hi,
I’m having troubles parsing some JSON stuff. I’m talking to an website API over Oauth and getting some JSON as return
Here’s some of my main.lua code:
local request\_response = oAuth.makeRequest("http://api.mysite.com/users/list.json", params, consumer\_key, access\_token, consumer\_secret, access\_token\_secret, "GET" )
local myCode\_encoded = json.encode(request\_response)
local myCode\_decoded = json.decode(myCode\_encoded)
print (myCode\_decoded)
This outputs the following JSON:
[{"id":"1","email":"some@email.com","username":"someuser","firstname":"James","lastname":"Wilson","country":"UK","city":"London","address":"Oxfordstreet 55","latlng":"50.12345,3.123456","work":"Developer","sex":"male","biography":"Apple fan, ...","gardenSize":"950.00"},{"id":"2","email":"some@othermail.com","username":"azerty","firstname":"Rick","lastname":"Astley","country":"UK","city":"London","address":"Oxfordstreet","latlng":"","work":"","sex":"male","biography":""}]
How do i select the separate nodes for each record ?
This doesn’t work:
print(myCode\_encoded.id[1])
It gives me an error:
Runtime error: main.lua:37: attempt to index field ‘id’ (a nil value)
Who can help me on my way ?
Thx
Lieven [import]uid: 13439 topic_id: 13134 reply_id: 313134[/import]
