Hi every one,
I am working on Json Parsing....In that I am
facing problem in Convert String into JsonObject....Please Help
me!!!!!!
Here is the code I got
class MyTask extends AsyncTask<String, Void, String> {
ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Loading...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
return Utils.getJSONString(params[0]);
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (null != pDialog && pDialog.isShowing()) {
pDialog.dismiss();
}
if (null == result || result.length() == 0) {
showToast("No data found from web!!!");
MainActivity.this.finish();
} else {
try {
System.out.println("Monaaaaaaaaaaaaa"+result);
Toast.makeText(getApplicationContext(),
""+result, 1000).show();
JSONObject mainJson = new
JSONObject(result);
System.out.println("Monaaaaaaaaaaaaa"+mainJson);
JSONArray jsonArray =
mainJson.getJSONArray(ARRAY_NAME);
for (int i = 0; i < jsonArray.length();
i++) {
JSONObject objJson =
jsonArray.getJSONObject(i);
Item objItem = new Item();
objItem.setId(objJson.getInt(ID));
objItem.setName(objJson.getString(NAME));
//
objItem.setCity(objJson.getString(CITY));
//
objItem.setGender(objJson.getString(GENDER));
//
objItem.setAge(objJson.getInt(AGE));
//
objItem.setBirthdate(objJson.getString(BIRTH_DATE));
arrayOfList.add(objItem);
}
} catch (JSONException e) {
e.printStackTrace();
}
Thanks.....
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en