Sorry for my limited english first.
I have a JSON sent from a POST request to my spring controller in Java.
I need parse this JSON to a Array. How I can do this?
Thanks!
Another option would be to use json-smart
Convert JSON to an object
JSONObject jsonObj = (JSONObject) JSONValue.parseWithException(inputJsonInStringFormat);
Retrieve array by using get() method
Integer [] intArray = (JSONArray) (JSONObject) jsonObj.get("arrayName");
using javax.json library, it should be something like:
JsonReader reader = Json.createReader(new FileInputStream(dir));
JsonArray re = (JsonObject) reader.read() ;
double[] ret = new double[jre.size()];
for ( int i = 0; i<jre.size(); i++)
ret[i] = Double.parseDouble( jre.getString(i) );
It does depend, however, on what the Json file looks like. Maybe it's a Json object, with one parameter which has an array as a value, or something. I hope this code can give you a headstart though.
you should not handle it by your-self let spring mvc do it for you, once you enabled spring mvc annotation you will have json converter implicitly, you will need only to add jackson jars to classpath, check this video https://www.youtube.com/watch?v=DnDCJjjSiu8 , your may face problem if want to send JSON as ["value1","value2"], in this case you will need to make custom JsonDeserializer
gsonlibrary. And show us some code.this JSON-- > Which JSON ?a JSON sent from a POST request;)