JSON parsing on Android [duplicate] - android

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Parsing a 2D JSON array in Android and then putting them in intents and getting their values in another activity
I am making an Android applications in which I am getting the following response. I need to parse this using JSON parsing and take these to next activity:
[
{
"sno": "131",
"email": "ruma.riwaz#gmail.com",
"place": "43",
"description": "",
"image": "",
"time": "1316156532"
},
{
"sno": "130",
"email": "ruma.riwaz#gmail.com",
"place": "38",
"description": "",
"image": "",
"time": "1316153291"
},
{
"sno": "365",
"email": "ruma.riwaz#gmail.com",
"place": "86",
"description": "",
"image": "",
"time": "1318427821"
},
{
"sno": "129",
"email": "ruma.riwaz#gmail.com",
"place": "39",
"description": "",
"image": "",
"time": "1316152314"
},]
How do I fix this problem?

I think you should try searching it on Google or in StackOverFlow it self (this could be duplicate question)....
any way;
You should use either Gson or Jackson

Related

how to read this JSON format [duplicate]

This question already has answers here:
How do I parse JSON in Android? [duplicate]
(3 answers)
Closed 4 years ago.
My JSON:
[
{
"productid": "3",
"name": "Potato",
"price": "15",
"quantity": "",
"stock": "0",
"description": "Fresh and good",
"image1": "upload/Potato1.jpg",
"image2": "upload/Potato2.jpg",
"image3": "upload/Potato3.jpg",
"status": "Out of Stock",
"type": "Vegetables"
},
{
"productid": "5",
"name": "Tomato",
"price": "25",
"quantity": "",
"stock": "45",
"description": "Fresh and good",
"image1": "upload/Tomato1.jpg",
"image2": "upload/Tomato2.jpg",
"image3": "upload/Tomato3.jpg",
"status": "Avaiable",
"type": "Vegetables"
},
{
"productid": "4",
"name": "Onion",
"price": "30",
"quantity": "",
"stock": "50",
"description": "Fresh and good",
"image1": "upload/Onion1.jpg",
"image2": "upload/Onion2.jpg",
"image3": "upload/Onion3.jpg",
"status": "Avaiable",
"type": "Vegetables",
"wishlistid": "43",
"userid": "10",
"flag": "1"
},
{
"productid": "6",
"name": "Carrot",
"price": "20",
"quantity": "",
"stock": "50",
"description": "Fresh and good",
"image1": "upload/Carrot1.jpg",
"image2": "upload/Carrot2.jpg",
"image3": "upload/Carrot3.jpg",
"status": "Avaiable",
"type": "Vegetables",
"wishlistid": "47",
"userid": "10",
"flag": "1"
}
]
In this first 2 json object have few column missing like userid and wishlistid and flag and remaining are having the userid, wishlistid and flag.
How can I read this with retrofit library .. because it gives me nothing as there is no userid column found in the first 2 objects.
You can parse json tow way one is manual or other using parser like Gson, Also better for both you create pojo class which help you.
String yourJsonString=jsondata;
JSONArray jsonArray= null;
try {
jsonArray = new JSONArray(yourJsonString);
if(jsonArray!=null && jsonArray.length()>0){
//Here you can parse tow way one is manual or other one using gson
//1.Manual one
for(int pos=0;pos<jsonArray.length();pos++){
JSONObject jsonObject=jsonArray.getJSONObject(pos)
//Here you can parse your object tow one is pass all value by manual
//like YourModelObject.setMethod(jsonObject.getString("keyName");
//Or other one is create model class and parse data using gson like following
/*CustomModel modelObj= new Gson().fromJson(jsonObject, new TypeToken<LocationHoModel>() {
}.getType());*/
}
//2.Using Gson
/*ArrayList<CustomModel> customModelArrayList = new Gson().fromJson(jsonArray, new TypeToken<ArrayList<CustomModel>>() {
}.getType());*/
}
} catch (JSONException e) {
e.printStackTrace();
}

Get the data from the JsonArray [duplicate]

This question already has answers here:
org.json.JSONArray cannot be converted to JSONObject
(5 answers)
Closed 5 years ago.
this is my JSON result when I print the log.I am not able to get the data from this result.Please suggest how to get the data from this result. The error shows the of type org.json.JSONArray cannot be converted to JSONObject.I know there are already many posts related to this but I can't understand how to get the data.
09-12 05:12:57.606: W/System.err(3385): org.json.JSONException: Value
[
{
"client": [
{
"office_name": "",
"is_verified": "1",
"forum_email_notification": "1",
"city": "",
"first_name": "Pratik",
"balance": "0",
"option_domain_name": "Vision",
"initials": "Mr",
"client_type": "0",
"group_credit": "0.00",
"gender": "0",
"is_approved": "1",
"domain_name": "Vision",
"client_id": "2",
"otherim": "",
"credit": "0.00",
"is_spam": "0",
"office_phone": "",
"parent_id": "0",
"domain_url": "http://example.com/vision4/sandip/v5/",
"fax": "",
"forum_signature_content": "",
"group_id": "1",
"optionB_domain_id": "1",
"country": "",
"contact_number": "",
"user_name": "test",
"email": "pratik#test.com",
"job_title": "",
"last_name": "T",
"parent_name": "",
"temporary_address": "",
"facebook_id": "",
"language": "1",
"office_contact_num": "",
"salt": "e2e838b89b16f488a901b3b364ad839e",
"zip_code": "",
"office_website": "",
"department": "",
"state": "",
"office_fax": "",
"login_as": "0",
"currency": "USD",
"permanent_address": "",
"department_access": "0",
"is_manager": "0",
"birthdate": "",
"registration_date": "1504254310",
"parent_email": "",
"password_auth": "0",
"group_name": "Default",
"netmeetingid": "",
"website": "",
"domain_id": "1",
"is_banned": "0",
"twitter_id": "",
"mobile_number": "",
"office_address": "",
"authentication": "383Y4A==",
"harvest_id": "0",
"image_path": "",
"office_email": ""
}
],
"unsolve": 3,
"solve": 0
}
]
of type org.json.JSONArray cannot be converted to JSONObject
It's because your result is an array of JSONObject and not a JSONObject itself

How to pass object of json to other activity

I have this json
{
"results": [{
"gender": "male",
"name": {
"title": "mr",
"first": "isidro",
"last": "nogueira"
},
"location": {
"street": "3663 rua amazonas ",
"city": "mesquita",
"state": "rio de janeiro",
"postcode": 27744
},
"email": "isidro.nogueira#example.com",
"login": {
"username": "orangegoose315",
"password": "redalert",
"salt": "Dd3U7U03",
"md5": "325f1e8753222facba6ee63a5e2451de",
"sha1": "a63a0c544a956e235330b0ed76d11d3ad17c7979",
"sha256": "ddf18ffff89684617b2c7b8c5c175b9570cb6005916d9b4f3face802bd4f13a1"
},
"dob": "1967-04-23 04:58:32",
"registered": "2016-05-08 01:56:44",
"phone": "(11) 8368-8583",
"cell": "(17) 9743-3074",
"id": {
"name": "",
"value": null
},
"picture": {
"large": "https://randomuser.me/api/portraits/men/57.jpg",
"medium": "https://randomuser.me/api/portraits/med/men/57.jpg",
"thumbnail": "https://randomuser.me/api/portraits/thumb/men/57.jpg"
},
"nat": "BR"
}],
"info": {
"seed": "5b3dff5c25caaf7f",
"results": 1,
"page": 1,
"version": "1.1"
}
}
This data is of just one user. I have 50 of them.
I am still in learning stage and what I have done is that I have successfully listed all user in an activity. Now what I want to do is when I click on a user it should show it's related details in next activity...
List Users->Select Users->Show selected user details
I still don't know how to send data to other activity and display it.

Image loading From java server to android Listview

I am developing an android application. I need to load images from a java server to Android Recyclerview or Listview.
I understand the android side of things via this thread http://www.androidhive.info/2014/06/android-facebook-like-custom-listview-feed-using-volley/.
I need help with the Java Server side.I need to retrive Images via JSON array. like this
{
"feed": [
{
"id": 1,
"name": "National Geographic Channel",
"image": "http://api.androidhive.info/feed/img/cosmos.jpg",
"status": "\"Science is a beautiful and emotional human endeavor,\" says Brannon Braga, executive producer and director. \"And Cosmos is all about making science an experience.\"",
"profilePic": "http://api.androidhive.info/feed/img/nat.jpg",
"timeStamp": "1403375851930",
"url": null
},
{
"id": 2,
"name": "TIME",
"image": "http://api.androidhive.info/feed/img/time_best.jpg",
"status": "30 years of Cirque du Soleil's best photos",
"profilePic": "http://api.androidhive.info/feed/img/time.png",
"timeStamp": "1403375851930",
"url": "http://ti.me/1qW8MLB"
},
{
"id": 5,
"name": "Abraham Lincoln",
"image": null,
"status": "That some achieve great success, is proof to all that others can achieve it as well",
"profilePic": "http://api.androidhive.info/feed/img/lincoln.jpg",
"timeStamp": "1403375851930",
"url": null
},
{
"id": 3,
"name": "Discovery",
"image": "http://api.androidhive.info/feed/img/discovery_mos.jpg",
"status": "A team of Austrian scientists has developed a laser system that causes fruit flies to dance.",
"profilePic": "http://api.androidhive.info/feed/img/discovery.jpg",
"timeStamp": "1403375851930",
"url": "http://dsc.tv/xmMxD"
},
{
"id": 4,
"name": "Ravi Tamada",
"image": "http://api.androidhive.info/feed/img/nav_drawer.jpg",
"status": "Android Sliding Menu using Navigation Drawer",
"profilePic": "http://api.androidhive.info/feed/img/ravi_tamada.jpg",
"timeStamp": "1403375851930",
"url": "http://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/"
},
{
"id": 6,
"name": "KTM",
"image": "http://api.androidhive.info/feed/img/ktm_1290.jpg",
"status": "\"The Beast\" KTM 1290 Super Duke",
"profilePic": "http://api.androidhive.info/feed/img/ktm.png",
"timeStamp": "1403375851930",
"url": ""
},
{
"id": 7,
"name": "Harley-Davidson",
"image": "http://api.androidhive.info/feed/img/harley_bike.jpg",
"status": "We’re assembling riders of every style, bike, and passion. If you ride with conviction, ride with us. You have 24 days to get ready for World Ride. Prepare by visiting:",
"profilePic": "http://api.androidhive.info/feed/img/harley.jpg",
"timeStamp": "1403375851930",
"url": "http://bit.ly/1wmBWaN"
},
{
"id": 8,
"name": "Rock & Girl",
"image": "http://api.androidhive.info/feed/img/rock.jpg",
"status": "A long time back...",
"profilePic": "http://api.androidhive.info/feed/img/rock_girl.jpg",
"timeStamp": "1403375851930",
"url": ""
},
{
"id": 8,
"name": "Gandhi",
"image": null,
"status": "An eye for an eye will make the whole world blind.",
"profilePic": "http://api.androidhive.info/feed/img/gandhi.jpg",
"timeStamp": "1403375851930",
"url": ""
},
{
"id": 9,
"name": "LIFE",
"image": "http://api.androidhive.info/feed/img/life_photo.jpg",
"status": "In 1965, LIFE photographer Bill Ray spent weeks with the Hells Angels, but his amazing photos never ran in the magazine",
"profilePic": "http://api.androidhive.info/feed/img/life.jpg",
"timeStamp": "1403375851930",
"url": "http://ti.me/1rfcQa4"
},
{
"id": 10,
"name": "Shakira",
"image": "http://api.androidhive.info/feed/img/shakira_la_la.png",
"status": "Download La La La (Brazil 2014) from iTunes:",
"profilePic": "http://api.androidhive.info/feed/img/shakira.jpg",
"timeStamp": "1403375851930",
"url": "http://smarturl.it/FWCalbum?IQid=sh"
},
{
"id": 11,
"name": "A. R. rahman",
"image": "http://api.androidhive.info/feed/img/ar_bw.jpg",
"status": "",
"profilePic": "http://api.androidhive.info/feed/img/ar.jpg",
"timeStamp": "1403375851930",
"url": ""
}
]
}
and how to get the Image url in from server side like this
You can used picasso library.
Picasso.with(context).load("http://api.androidhive.info/feed/img/cosmos.jpg").placeholder(R.drawable.no_image).into(imageView);

get post which contain hashtag android facebook android

I am trying to fetch the json data of the post which contains specific hashtag
for eg if u go to this fb link u will get the post which contaihs the hashtag https://www.facebook.com/hashtag/tajmahal
I have treid various ways
graph.facebook.com/search?q=%23tajmahal&type=post&access_token={ACCESS_TOKEN}
It gives Post search has been deprecated","type":"OAuthException"
graph.facebook.com/search?q=%23tajmahal&type=place&access_token={ACCESS_TOKEN}
It gives all the places which have tajmahal in their name
"category": "Landmark",
"category_list": [
{
"id": "209889829023118",
"name": "Landmark"
}
],
"location": {
"street": "",
"city": "Agra",
"state": "",
"country": "India",
"zip": "",
"latitude": 27.174799,
"longitude": 78.042111
},
"name": "Tajmahal",
"id": "108571669173264"
},
{
"category": "Local business",
"category_list": [
{
"id": "165679780146824",
"name": "Food & Restaurant"
}
],
"location": {
"street": "agra",
"city": "Agra",
"state": "",
"country": "India",
"zip": "",
"latitude": 27.192731328938,
"longitude": 78.026342496684
},
"name": "Tajmahal Agra",
"id": "339553856132817"
},
{
"category": "Automobiles and parts",
"category_list": [
{
"id": "149998721725634",
"name": "Automotive Repair"
}
],
"location": {
"street": "opposite to MARS Shopping, Shafi street, Rayyan Jadheedh",
"city": "Al Rayyan",
"state": "",
"country": "Qatar",
"zip": "001",
"latitude": 25.2902476,
"longitude": 51.4204253
},
"name": "Tajmahal automobiles",
"id": "191178317741786"
so anyone can suggest a way to get the post which have certain hashtag from facebook?
Facebook closed access to that endpoint
http://thenextweb.com/facebook/2015/04/03/facebook-might-be-shutting-down-access-to-hashtags-in-its-api/

Categories

Resources