I have a json input like this
[ {
"Company":"BEG",
"Account":"1001",
"Deptid":"",
"Location":"",
"Transaction Date":"2014-07-15",
"Description":"Invoice",
"Debit":0.0,
"Credit":13.46,
"Invoice Nbr":"1682"
},
{
"Company":"BEG2",
"Account":"1002",
"Deptid":"23",
"Location":"NY",
"Transaction Date":"2014-07-15",
"Description":"Invoice",
"Debit":0.0,
"Credit":13.45,
"Invoice Nbr":"1682432"
},
....
....
},
{
"Company":"BEG99",
"Account":"1099",
"Deptid":"",
"Location":"",
"Transaction Date":"2014-07-15",
"Description":"Invoice",
"Debit":0.0,
"Credit":13.46,
"Invoice Nbr":"168243299"
}]
I am using json simple jar to parse the json. my code is:
public String appendData(String str) throws IOException, ParseException{
System.out.println("========Inside appendData======"+str);
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject) jsonParser.parse(new StringReader(str));
double debit = (double) Double.parseDouble(jsonObject.get("Debit").toString());
}
Above code works fine, If i send single lock of data and without [ and ] bracket. Above json is a valid json according to JSONLint
Question:
1) How do I parse above json having multiple data?
[]indicates a JSON "array", yet you're apparently trying to parse it as an "object". If you understood the syntax you wouldn't make this error.