Hi.
I have encountered a problem where my JSON responses, returned by the server, are being improperly parsed. JSON responses such as:
will give me two records, each containing a string("Server network,DNS resolver" and "WiFi,Client network") for the email DataSourceField.
However, if i change the server to send responses in XML, such as this :
I will get two records containing arrays(["Server network", "DNS resolver"] and ["WiFi", "Client network"]) in the email field.
Why is this?
I have seen in the docs that you parse JSON responses with JavaScripts eval() function. Running eval() on the JSON response above will give me the correct result. I have tried to located the problem in transformResponse(), but even doing a JSONObject(dsResponse.getDataAsObject()).toString()) gives the wrong result.
Test case:
rules.py will return the XML response above, and rules2.py will return the JSON response above.
Then in the developer console, one can do isc_ListGrid_1.getRecord(1)["email"] and isc_ListGrid_1.getRecord(1)["email"] to see the differences.
SmartClient Version: v11.0p_2016-07-05/LGPL Development Only (built 2016-07-05)
Chromium Version 50.0.2661.102 Ubuntu 14.04 (64-bit)
I have encountered a problem where my JSON responses, returned by the server, are being improperly parsed. JSON responses such as:
Code:
{ "response": { "status": 0, "startRow": 0, "totalRows": 2, "data": [{ "email": ["Server network", "DNS resolver"] }, { "email": ["Wifi", "Client network"] }], "endRow": 1 } }
However, if i change the server to send responses in XML, such as this :
Code:
<?xml version="1.0" encoding="UTF-8" ?> <response> <status>0</status> <startRow>0</startRow> <totalRows>2</totalRows> <data> <rule> <email>Server network</email> <email>DNS resolver</email> </rule> <rule> <email>WiFi</email> <email>Studentby</email> </rule> </data> <endRow>1</endRow> </response>
Why is this?
I have seen in the docs that you parse JSON responses with JavaScripts eval() function. Running eval() on the JSON response above will give me the correct result. I have tried to located the problem in transformResponse(), but even doing a JSONObject(dsResponse.getDataAsObject()).toString()) gives the wrong result.
Test case:
rules.py will return the XML response above, and rules2.py will return the JSON response above.
Code:
public void onModuleLoad() { VLayout layout = new VLayout(); layout.setHeight100(); layout.setWidth100(); RestDataSource ds = new RestDataSource(); RestDataSource ds2 = new RestDataSource(); DataSourceTextField dataSourceTextField = new DataSourceTextField("email"); dataSourceTextField.setMultiple(true); ds.setFields(dataSourceTextField); ds.setDataURL("rules.py"); ds2.setFields(dataSourceTextField); ds2.setDataURL("rules2.py"); ds2.setDataFormat(DSDataFormat.JSON); ListGridField listGridField = new ListGridField("email", "Email alert"); ListGrid grid = new ListGrid(); grid.setDataSource(ds); grid.fetchData(); grid.setFields(listGridField); ListGrid grid2 = new ListGrid(); grid2.setDataSource(ds2); grid2.fetchData(); grid2.setFields(listGridField); layout.setMembers(grid, grid2); layout.show(); } }
SmartClient Version: v11.0p_2016-07-05/LGPL Development Only (built 2016-07-05)
Chromium Version 50.0.2661.102 Ubuntu 14.04 (64-bit)
Comment