i use all ways to transfer array from php to js but the best solution is to use
JSON_encode($arr);
and all way to decode it fail
finally i decide to do it manually where the data received in JavaScript are like this: [“208″,”2812”] which converted to integer array by this java code but i don’t know how to transfer it to javascript
String arr = "[\"208\",\"2507\"]";
//this its the output of him ["208","2507"]
String[] items = arr.replaceAll("\\[", "").replaceAll("\\]", "").split(",");
int[] results = new int[items.length];
for (int i = 0; i < items.length; i++) {
results[i] = Integer.parseInt(items[i]);
}
Given a string in JSON format like you have:
You can get an actual array with:
Though that contains strings. To turn the strings into integers:
Or in one line:
But if you need the items in the array to be integers, why don’t you just output integers in the first place, rather than strings:
Then all you need is: