http://docs.blackberry.com/sampledata.json
This is my web service and I want to parse and retrieve vehicleType, vehicleColor, fuel, name, experiencePoints, treadType
you can use this class :
just make the object of this class and call the method!!
public class JSONParser {
private static String result;
private static String resultArr;
public static String getJSONArr (String json,String tag1,int arrNum)
{
try {
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
if(i==arrNum){
JSONObject row = array.getJSONObject(i);
resultArr = row.getString(tag1);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return resultArr;
}
public static String getJSONObj (String json,String tag1)
{
try {
JSONObject jObj = new JSONObject(json);
if(jObj.has(tag1))
result = jObj.getString(tag1);
else
Log.d("JSON ERROR", "tag not found");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}