Hi guys,
I'm having a hard time parsing the json string below. Can you please help? This is a simplified version:
{
"meta": {
"limit": 20,
},
"objects": [
{
"cat_pai": null,
"desc": "Cat Test Desc 1",
"id": 5315423,
"name": "Cat Nome Teste 1"
}
]
}
//My code
String ls_ret, ls_meta, ls_obj
Long ll_ret, ll_root, ll_limit, ll_tot, ll_obj, ll_id
JSONPackage ljpkg
JSONParser ljp
String ls_j = '{"meta": {"limit": 20},"objects": [{"cat_pai": null,"desc": "Cat Test Desc 1","id": 5315423,"name": "Cat Nome Teste 1"}]}'
ljpkg = Create JSONPackage
ljp = Create JSONParser
//I was able to use JSONPackage and get the values from "meta".
ls_ret = ljpkg.LoadString(ls_j)
ls_meta = ljpkg.GetValue('meta')
ls_ret = ljp.LoadString(ls_meta)
ll_root = ljp.GetRootItem()
ll_limit = ljp.GetItemNumber(ll_root, 'limit')
//Well, then I wasn't able to parse the "objects" array. I tried using this code below, but I can't get the "id" value, it always returns null. Can you please help?
ls_obj = '{"objects": ' + ljpkg.GetValue('objects') + '}' //weird I had to do this concat, is it really necessary? Otherwise the GetChildCount would return 2, and I couldn't find a way to use GetItemArray
ls_ret = ljp.LoadString(ls_obj)
ll_root = ljp.GetRootItem()
ll_tot = ljp.GetChildCount(ll_root) //Seems to be working
If ll_tot = 0 Then Return
ll_obj = ljp.GetItemArray(ll_root, 'objects') //I expected ll_obj would return 1, but it returns 2. Why?
ll_id = ljp.GetItemNumber(ll_obj, 'id') //this always returns null :(
Thanks a lot