0

I need to give a JSONArray with a JSONObject to a JavaScript function that will pass these parameters to Java.

What I tried so far, that did NOT work:

//wrong syntax

var array = [[1, 1, "DescPDV1"]];

//right sintax, but works only as JSONArray, not JSONObject inside JSONArray

var array = [1, 1, "DescPDV1"];

//worng syntax

var array = [{1, 1, "DescPDV1"}];

//wrong syntax

var array = {1, 1, "DescPDV1"};

//wrong syntax

var array = {{1, 1, "DescPDV1"}};

My JSONObject is full of values, but no key addressed to them, then, no ["id" : "1", "blah" : "2"]... just the values [1, ""blah"].

What Im doing wrong?

1 Answer 1

2

If your JSONObject does not have keys, then it is not an object. You need to represent it as an array of arrays like this:

[[1, 1, "DescPDV1"]]

This is a valid JSON string, as can be confirmed at JSONLint

Also, this is valid Javascript:

var array = [[1, 1, "DescPDV1"]];

As can be confirmed here at JSFiddle

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.