I had following json format :
[
{ "Otype" : "win"},
{ "Otype" : "win"},
{ },
{ },
{ "Otype" : " win 7"},
{ "Otype" : " Linux"}
]
for accessing Otype I write java code as below:
while(cur.hasNext() && !isStopped()) {
String json = cur.next().toString();
JSONObject jObject = new JSONObject(json);
System.out.print(jObject.getString("Otype"));
}//end of while
So above print statement print only following results:
win
win
but not print:
{ "Otype" : " win 7"}
{ "Otype" : " Linux"}
I think it may be first white space in value field that's why it not print above two key so I changed in print statement as below:
System.out.print(jObject.getString("Otype").trim());
but still not work :( .
How I can access all above json value using java code?
{ }) will cause a problem when you try to access theOtypefield. Did the code throw an exception?