Comments (3)
Hi, here is one way to do this :
ls_error = ln_json.parse('[{"route":"Transaction","service_status":"Active","balance":82,"validity":"2022-08-11T18:30:00.000Z"},{"route":"Promotional","service_status":"Active","balance":100,"validity":"2022-12-30T18:30:00.000Z"}]')
if ls_error = "" then
if ln_json.isarray() then
any la_array[]
la_array[] = ln_json.getarray()
messagebox("array length:", string( upperbound( la_array[] ) ) )
ln_json.retrieve("1/route", ref la_data)
string ls_route
ls_route = la_data
messagebox("1st route:", ls_route)
end if
end if
from pbjson.
Thanks it works now had one more I if I had array as a element which hold array my code is as follows is there any better way to handle this?
int li_start, li_end
String ls_error, ls_response, ls_value
any la_data
any la_value
json ln_json
ln_json = create json
ls_response = '{"contents": [{"id" : "1", "name" : "one"},{ "id" : "2", "name" : "Two"}]}'
ls_error = ln_json.parse(ls_response)
if ls_error = "" then
ln_json.retrieve("contents", ref la_data)
li_end = upperbound( la_data[])
For li_start = 1 TO li_end
ln_json.retrieve("contents/" + String(li_start) + "/name", ref la_value)
MessageBox("Info", "Name : " + String(la_value))
NEXT
end if
destroy ln_json
from pbjson.
Hi, here is another way to do the same, using less retrieve() calls, so for huge array it should be faster:
int li_start, li_end
String ls_error, ls_response
any la_data, la_contents[]
json ln_json, ln_item
ln_json = create json
ls_response = '{"contents": [{"id" : "1", "name" : "one"},{ "id" : "2", "name" : "Two"}]}'
ls_error = ln_json.parse(ls_response)
if ls_error = "" then
ln_json.retrieve("contents", ref la_data)
la_contents[] = la_data
li_end = upperbound( la_contents[] )
For li_start = 1 TO li_end
ln_item = la_contents[li_start]
MessageBox("Info", "Name : " + string(ln_item.getattribute("name")))
next
end if
destroy ln_json
from pbjson.
Related Issues (4)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pbjson.