I am trying to fetch the list of pathological tests from my server from the API https://dakshalab.com/dakshalab/admin/api.php?apicall=test_list and display it on my app. For this purpose I have written the following code:
var loader1 = new URLLoader();
var url1 = new URLRequest("https://dakshalab.com/dakshalab/admin/api.php?apicall=test_list");
loader1.load(url1);
var json;
loader1.addEventListener(Event.COMPLETE, (event:Event) -> {
var loader = cast(event.currentTarget, URLLoader);
var data = Std.string(loader.data);
json = haxe.Json.parse(data);
trace("test_list: "+json.test_list[0]);
for(obj in json.test_list)
{
var obj1 = haxe.Json.stringify(obj);
trace(obj1);
var obj2 = haxe.Json.parse(obj1);
trace(obj2);
trace(obj2.name);
listView.dataProvider.add({"text": obj2.name});
}
});
This code is working fine in browser. In the browser console I view the output like below:
src/pages/TestListPage.hx:121: {"id":"19","name":"BLOOD Grouping"}
MyApplication.js:37776 src/pages/TestListPage.hx:123: {
id : 19,
name : BLOOD Grouping
}
MyApplication.js:37776 src/pages/TestListPage.hx:124: BLOOD Grouping
This is the output of one of the iteration of for loop.
But when I am running the same code in the android using command openfl test android -debug then I am getting output like below:
07-07 23:51:19.639 11881 11936 I trace : src/pages/TestListPage.hx:121: "{ name => BLOOD Grouping, id => 19 }"
07-07 23:51:19.639 11881 11936 I trace : src/pages/TestListPage.hx:123: { name => BLOOD Grouping, id => 19 }
07-07 23:51:19.639 11881 11936 I trace : src/pages/TestListPage.hx:124: null
So it looks like the stringify function is working differently. In case of browser the stringify function is generating the output like {"id":"19","name":"BLOOD Grouping"} but in case of android app the stringify function is generating output like "{ name => BLOOD Grouping, id => 19 }". Due to this the JSON is not parsed correctly on android app and so the value of obj2.name is displayed as null in case of android app.
Can you please figure out why stringify function is working differently on both platforms? How to fix this problem?