Q:
My json file looks like this:
Code:
{"dbobjects":
[
{"name": "Template", "type": "table"},
{"name": "ADAttributes", "type": "table"}
]
}
I am using the code below to iterate through the dynamic array but I get a compile error
Code:
jsonDBOs = json_decode_file(filePath)
foreach jsonDBOs.dbobjects as dbo1
//Do Something
endfor
**** Lianja error ****
foreach jsonDBOs.dbobjects as dbo1
^
IN was expected
Called from program - dbupgrade.prg at line 30
Called from procedure - page1_section2_field1_click at line 4
I tried declaring jsonDBOs as a dynamic array but that didn't work. jsonDBOs.dbobjects is a valid array if I access it manually in the debug console.
A:
Try creating a reference to the array:
Code:
adbo = jsonDBOs.dbobjects
foreach adbo as dbo1
? dbo1.name
? dbo1.type
endfor
an array name or object name should be specified not an expression.
Q:
Is there a way I can consume Odata data in the desktop?
I was thinking that geturl() should work, but I am not having any luck with that.
I thought that this might work, but looking in fiddler, there is nothing being sent.
Code:
filename = geturl("http://localhost:8001/odata/southwind/customers", 30, array(), "myfilename.json")
if len(filename) = 0
wait window "no data"
else
wait window "file has Data"
endif
No luck at the moment.
Running this
Code:
filename = Lianja.odata_read("http://localhost:8001/odata/southwind/customers", "myfilename.json")
I am getting the following.
**** Lianja JavaScript error ****
Traceback (most recent call last):
page1_section1.js at 10
<global>() at 1TypeError: Result of expression 'Lianja.odata_read' [undefined] is not a function.
A:
The OData functions were not available in JavaScript custom sections.
I have now added the OData functions to the Lianja system object for JavaScript/Python/PHP desktop apps (already in web and mobile), so these will be available in the next beta build.
Code:
var jsonstring = Lianja.OData_Create(url, jsonstring);
var jsonstring = Lianja.OData_Read(url);
var jsonstring = Lianja.OData_Update(url, jsonstring);
var jsonstring = Lianja.OData_Delete(url, jsonstring);
This is an example of manually updating the data in a webview.
This uses the Lianja.Odata_update() method.
You don't need any PHP or ASP.net code, it handle that all for you in a simple function call.
Lianja OdataUpdate - https://youtu.be/etedfN6h3_I
Q:
I need to populate an array with data from a json file,but did not want to use subscripts to access the data in the array e.g. array[1,1] but access them as objects just like a table.
A:
Try this approach:
Code:
open database southwind
select * from categories into json xxxx
ss=json_decode_file("xxxx.txt")
*?ss // view all array elements
*?ss.row7.categoryname // referencing a subelement of dynamic array
for ii=1 to alen(ss)
num=alltrim(str(ii))
catid="ss.row"+num+".categoryid"
catname="ss.row"+num+".categoryname"
x1=&catid
x2=&catname
? x1
? x2
endfor
Result:
1
Beverages
2
Condiments
3
Confections
4
Dairy Products
5
Grains/Cereals
6
Meat/Poultry
7
Produce
If you use SQL select like I did here, the same is accomplished with INTO OBJECT:
Code:
select * from categories into object ss
Referencing is the same.
Code:
?ss.row7.categoryname // referencing a subelement
All topics in [Answers] alphabetically: http://www.lianja.com/community/show...p?2717-Answers
Bookmarks