Pass json object from android(java) to javascript in Webview

Viewed 2567

I am working on an Android Webview Application.I need to call a function from Javascript and the Java function should return a JSON object.If the there is only one value in my JSON object i could access it from Javascript.But if there is more than one i get the value undefined.

ex: In Java method

JSONObject ob = new JSONObject();
ob.put("hello","hai");
return String.valueOf(ob);

In Javascript

data = app.getValue();
obj = JSON.parse(data)
console.log(obj.hello);

The above code works Fine but,

In Java method

JSONObject ob = new JSONObject();
ob.put("hello","hai");
ob.put("abc","xyz");
return String.valueOf(ob);

In Javascript

data = app.getValue();
obj = JSON.parse(data)
console.log(obj.hello); <- doesn't work
console.log(obj[0].hello); <- doesn't work
1 Answers
Related