简体   繁体   中英

How to parse JSON response?

I have called webservice and got a response as below please tell me how can I parse it.....

FillAutoCompleteBudgetMasterItemsByMasterIdResponse{
FillAutoCompleteBudgetMasterItemsByMasterIdResult=anyType{
string=Agrochemicals; string=Certification fee; string=Consultation; 
string=Contracts; string=Electricity; string=Fertilizers; string=Fuel;
string=Implements and Equipments; string=Insurance; string=Irrigation and Water;
string=Labours; string=Machinery usage; string=Marketing; string=Other Items; 
string=Post Production; string=Repairs and Maintenance; string=Seeds/Seedlings ;
string=Services; string=Training; string=Transportation; }; }

This not a valid Response data.Beacuse it should contain a (key,value). By using key we get the value.

JSONArray arObjects = new JSONArray(Respone);for(int i = 0; i < arObjects.length(); i++)
JSONObject jOb =  arObjects.getJSONObject(i);                       
String date = jOb.getString("PublishedDate");
String price = jOb.getString("introduction");

This is not a valid json. The strings are not quoted.

http://json.org/example.html

this is not valid json format.. you cant parse using Json... if the string is not in the valid json format it throws an exception ... The String in enclosed [] braces in called josn array.. The String in enclosed {} braces in called josn object.. in general json array contain josn objects

JSONArray array= new JSONArray(jsonString);
for(i=0;i< array.length ;i++){
   JSONObject result = new JSONObject(array.get(i));
}

This tutorial might help you to parse the json in an easy and hassle free way. Please check this out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM