I have a properly formatted json array in a Java string, according to jsonlint. No matter what I try, the resulting JSONArray cadDims is empty. No exceptions reported. Here is attempt 1 code:
String dataStr = "[{\"DIMNAME\":\"d11\",\"DIMID\":\"11\"},{\"DIMNAME\":\"d12\",\"DIMID\":\"12\"}]";
try {
JSONArray cadDims = new JSONArray(dataStr);
} catch (JSONException ex) {
Logger.getLogger(EnCad.class.getName()).log(Level.SEVERE, null, ex);
}
Here is attempt 2:
String dataStr = "{\"dataStr\":[{\"DIMNAME\":\"d11\",\"DIMID\":\"11\"},{\"DIMNAME\":\"d12\",\"DIMID\":\"12\"}]}";
try {
JSONObject obj = new JSONObject(dataStr);
JSONArray cadDims = obj.getJSONArray("dataStr");
} catch (JSONException ex) {
Logger.getLogger(EnCad.class.getName()).log(Level.SEVERE, null, ex);
}
Here is attempt 3:
dataStr = "[{\"DIMNAME\": \"d11\",\"DIMID\": 11}, {\"DIMNAME\": \"d12\",\"DIMID\": 12}]";
try {
JSONArray cadDims = (JSONArray)new JSONTokener(dataStr).nextValue();
} catch (JSONException ex) {
Logger.getLogger(EnCad.class.getName()).log(Level.SEVERE, null, ex);
}