ich folgende JSON bin immer:Parsing Boolean JSON Wert immer gibt mir falsch
{
"ID": "479",
"id": "479",
"name": "Nishant Kango",
"last_logged": "1461225061",
"current_status": "icon-online prople-online",
"room_id": "d18f655c3fce66ca401d5f38b48c89af",
"current_user": false,
"lastmessage": [],
"userInfo": {
"id": "479",
"birthday": "1989-11-21",
"comment_privacy": "everyone",
"confirm_followers": "1",
"current_city": "Chandigarh, Chandigarh",
"follow_privacy": "everyone",
"gender": "male",
"hometown": null,
"message_privacy": "everyone",
"timeline_post_privacy": "a:1:{i:0;s:1:\"1\";}",
"feed_section": "1",
"post_privacy": "a:1:{i:0;s:1:\"5\";}",
"current_city_id": "1433",
"userSkills": ", Testing ",
"birth": {
"date": "21",
"month": "11",
"year": "1989"
},
"about": "asdasdasdas sad asd asd asd as",
"active": "1",
"avatar_id": "477",
"cover_id": "528",
"cover_position": "465",
"email": "[email protected]",
"email_verification_key": null,
"email_verified": "0",
"language": null,
"last_logged": "1461225061",
"name": "Nishant Kango",
"time": "0",
"timestamp": "2016-04-21 13:19:40",
"timezone": null,
"type": "user",
"username": "nishant",
"verified": false,
"user_id": "479",
"first_name": "Nishant",
"middle_name": null,
"last_name": "Kango",
"dob": "1989-11-21",
"mobile": "8699022278",
"title": null,
"marital_status": "single",
"childrens": "0",
"hobbies": "Travelling",
"interests": "Technology",
"feed_back": null,
"status": "approved",
"profile_pic": null,
"date_created": "2014-10-29 00:00:00",
"date_modified": "2016-03-31 19:07:56",
"activation_code": null,
"social_login_type": "facebook",
"facebook_id": "10205077190793111",
"linked_in_id": null,
"google_id": null,
"employment_status": null,
"is_deleted": "0",
"website": "http://www.nishantkango.com",
"reference_institute": "",
"industry": "0",
"proffesion_type": "",
"url": "http://192.168.2.250:82/user/timeline/e6b34e9a0311a7f829e09d2d7c4b313e",
"cover": {
"id": "528",
"active": "1",
"album_id": "0",
"extension": "jpg",
"name": "mentordirectorybgimagesuggestions6.jpg",
"post_id": "0",
"temp": "0",
"timeline_id": "0",
"type": "photo",
"url": "common/marvel/photos/2016/02/hqUDT_528_f4be00279ee2e0a53eafdaa94a151e2c",
"complete_url": "http://192.168.2.250:82/common/marvel/photos/2016/02/hqUDT_528_f4be00279ee2e0a53eafdaa94a151e2c.jpg",
"post_url": "/index.php?tab1=story&id=0"
},
"actual_cover_url": "http://192.168.2.250:82/common/marvel/photos/2016/02/hqUDT_528_f4be00279ee2e0a53eafdaa94a151e2c.jpg",
"cover_url": "http://192.168.2.250:82/common/marvel/photos/2016/02/hqUDT_528_f4be00279ee2e0a53eafdaa94a151e2c_cover.jpg",
"avatar": {
"id": "477",
"active": "1",
"album_id": "0",
"extension": "jpg",
"name": "10390233_10205765787487598_5674312231016706405_n.jpg",
"post_id": "0",
"temp": "0",
"timeline_id": "0",
"type": "photo",
"url": "common/marvel/photos/2016/01/yS1xw_477_74071a673307ca7459bcf75fbd024e09",
"complete_url": "http://192.168.2.250:82/common/marvel/photos/2016/01/yS1xw_477_74071a673307ca7459bcf75fbd024e09.jpg",
"post_url": "/index.php?tab1=story&id=0"
},
"thumbnail_url": "http://192.168.2.250:82/common/marvel/images/default-male-avatar.png",
"avatar_url": "http://192.168.2.250:82/common/marvel/images/default-male-avatar.png",
"online": true
}
}
Ich habe das Online/offine Status eines Benutzers innerhalb des userinfo object.I mit Online-Schlüssel überprüfen bin mit der folgenden Code:
JSONObject userInfo = object.getJSONObject("userInfo");
Boolean online = userInfo.getBoolean("online");
Log.e("Online",online);
Als ich versuchte, diese Aussage zu verwenden:
Log.e("online1", (String) userInfo.get("online"));
Es gibt mir den Fehler th at java.lang.ClassCastException: java.lang.Boolean kann nicht in java.lang.String umgewandelt werden.
So ist es sicher, dass userInfo.get („online“) mir einige boolean value.So zurückkehrt, wenn ich diese verwenden:
Log.e("online1", String.valueOf(userInfo.getBoolean("online")));
es mich immer falsch gibt, aber ich weiß, ich wahren Wert bin immer vom Server in einigen Fällen. Bitte helfen Sie mir, das Problem zu beheben
Das muss funktionieren .. Sind Sie sicher, dass Sie alles so machen? –
Sie können versuchen, boolean, die Eigenschaft und nicht Boolean das Objekt zu setzen. –
Alles ist in Ordnung mit Code, stellen Sie sicher, dass Sie denselben Code ausführen. – Ahsanwarsi