In my application i am trying to retrieve the values from a JSON URL. In the URL there is a point where I am not able to parser the values.. I have tried alot to find the solution but I haven’t got any..
In the URL the values that I want to parse is the values of tag_users…
I am attaching the code where I am trying to parser the values so, please help me in finding the solution…
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
String url = "http://flutterr.pnf-sites.info/api/messageshow/2";
JsonParser jParser = new JsonParser();
JSONObject json = jParser.getJSONfromUrl(url);
try
{
JSONArray messageshow = json.getJSONArray("messageshow");
userList.clear();
for(int i=0; i<messageshow.length();i++)
{
JSONObject msg = messageshow.getJSONObject(i);
message_id = msg.getString("message_id");
message = msg.getString("message");
message_pic = msg.getString("message_pic");
uid = msg.getString("uid");
created = msg.getString("created");
username = msg.getString("username");
first_name = msg.getString("first_name");
last_name = msg.getString("last_name");
profile_pic = msg.getString("profile_pic");
total_likes = msg.getString("total_likes");
JSONObject tag_user = msg.getJSONObject("tag_user");
message = tag_user.getJSONObject("tags").getString("message");
if(message != "false")
tag_uid = tag_user.getJSONObject("tags").getString("tag_uid");
Log.v("uid", tag_uid);
HashMap<String, String> map = new HashMap<String, String>();
map.put("message_id", message_id);
map.put("message", message);
map.put("message_pic", message_pic);
map.put("uid", uid);
map.put("created", created);
map.put("username", username);
map.put("first_name", first_name);
map.put("last_name", last_name);
map.put("profile_pic", profile_pic);
map.put("total_likes", total_likes);
userList.add(map);
}
}
catch(JSONException e)
{
Log.e("Error", e.toString());
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Please help me in letting me know that how can I parser the values of tag_uid, tag_uname, tag_fname and tag_lname…
try
if(!message.equals("false"))instead of
if(message != "false")One more thing check your server side code
in
tag_userthere isJson Objectwith nametagsin case of zero tags. And it is (tags) is aJsonArrayin case of results.EDIT
if you Json will look like this
and then in code you can get like
//will return “tag_uid” of first tag`