8

I am working with an android app that uses phonegap. The java calls some HTML that displays a web page and the HTML uses javascript for functions. Now in the javascript I make a JSON call using parameters from the HTML. The problem is I need to send this JSONArray back to the Java class. However, when I use

JavaActivity.parseJson(jsonArray.toString());

(where jsonArray is the JSONArray and parseJson is the method in the java activity)

the string that it sends looks something like this:

[{Object:Object}, {Object:Object}, {Object:Object}, .....]

What am I doing wrong or is there another way to convert this String, or just send the JSONArray directly?

2
  • The things in your jsonArray are apparently objects. The default implementation of Object.toString is "{Object:Object}". What sort of things are in the jsonArray? Commented Jul 9, 2012 at 16:23
  • 1
    Can you show us the javascript? Commented Jul 9, 2012 at 16:23

1 Answer 1

17

Assuming jsonArray holds all the data you want to send to Java do:

var jString = JSON.stringify(jsonArray);

Now 'jString' is the json encoded string representation of your array.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.