Related
I am trying to parse this file.
I am new to maps API so.
I am trying to parse this set into recyclerview
I trying to parse using String Request that works but I need json object to store data.
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Ahmedabad",
"short_name" : "Ahmedabad",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Suradhara Society",
"short_name" : "Suradhara Society",
"types" : [ "neighborhood", "political" ]
},
{
"long_name" : "Khodiar Nagar",
"short_name" : "Khodiar Nagar",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Ahmedabad",
"short_name" : "Ahmedabad",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Gujarat",
"short_name" : "GJ",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "382350",
"short_name" : "382350",
"types" : [ "postal_code" ]
}
],
"adr_address" : "3rd Floor, Sardar Patel Mall, Nikol Gam Road, \u003cspan class=\"street-address\"\u003eBapunagar\u003c/span\u003e, \u003cspan class=\"extended-address\"\u003eSuradhara Society, Khodiar Nagar\u003c/span\u003e, \u003cspan class=\"locality\"\u003eAhmedabad\u003c/span\u003e, \u003cspan class=\"region\"\u003eGujarat\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e382350\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eIndia\u003c/span\u003e",
"formatted_address" : "3rd Floor, Sardar Patel Mall, Nikol Gam Road, Bapunagar, Suradhara Society, Khodiar Nagar, Ahmedabad, Gujarat 382350, India",
"formatted_phone_number" : "085116 15040",
"geometry" : {
"location" : {
"lat" : 23.0379687,
"lng" : 72.6433222
},
"viewport" : {
"northeast" : {
"lat" : 23.0393176802915,
"lng" : 72.64467118029151
},
"southwest" : {
"lat" : 23.0366197197085,
"lng" : 72.64197321970849
}
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "7ddb8968d27481b07a700f6e34ac5442f528eaf2",
"international_phone_number" : "+91 85116 15040",
"name" : "Parsana Gym",
"photos" : [
{
"height" : 2322,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/104290859169763692879/photos\"\u003eAlpesh Patel\u003c/a\u003e"
],
"photo_reference" : "CmRaAAAAgWV9QS54sRCALTitzLBc7LowfL3gKMw_jbNaTSmeFM9GqqG6iu1hx4HJwj332LJQHpfk44xeAPIgYg0mexUJaoWd8mKIUt4oTUj0f-DvbmnrOG67Q5BwAh9eP6VjcPz3EhAHDkHpn52M8rURjiAncwzrGhTLyHQZ5qHXowonHaOnDvld63wrXg",
"width" : 4128
}
],
"place_id" : "ChIJEbpNLyCHXjkRny4b5TptHsY",
"plus_code" : {
"compound_code" : "2JQV+58 Ahmedabad, Gujarat, India",
"global_code" : "7JMJ2JQV+58"
},
"rating" : 4.4,
"reference" : "ChIJEbpNLyCHXjkRny4b5TptHsY",
"reviews" : [
{
"author_name" : "Sumit Patel",
"author_url" : "https://www.google.com/maps/contrib/101190972481759472779/reviews",
"language" : "en",
"profile_photo_url" : "https://lh3.googleusercontent.com/-70hcgZha3k4/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbDZJQHYZ86bOPzJBQjG8VNA0_Sh6g/s128-c0x00000000-cc-rp-mo/photo.jpg",
"rating" : 5,
"relative_time_description" : "4 months ago",
"text" : "gym is good and trainer are also good.\nbut some new machine are require for excersize.",
"time" : 1527730807
},
{
"author_name" : "Mahesh Bhayani",
"author_url" : "https://www.google.com/maps/contrib/105571914899766322779/reviews",
"language" : "en",
"profile_photo_url" : "https://lh3.googleusercontent.com/-EKevbjOaZsw/AAAAAAAAAAI/AAAAAAAAA4o/k75Wr5thZvg/s128-c0x00000000-cc-rp-mo/photo.jpg",
"rating" : 5,
"relative_time_description" : "4 months ago",
"text" : "Good atmosfiyar for parsana gym. Good service provide good trinar.",
"time" : 1527820640
},
{
"author_name" : "Nadiya Dipak",
"author_url" : "https://www.google.com/maps/contrib/100514831030336220877/reviews",
"language" : "en",
"profile_photo_url" : "https://lh6.googleusercontent.com/-he9oXwcUqLI/AAAAAAAAAAI/AAAAAAAAAAA/ABtNlbBq3ow6IHVx5QNQktTbXQEDI2v2xw/s128-c0x00000000-cc-rp-mo/photo.jpg",
"rating" : 5,
"relative_time_description" : "4 months ago",
"text" : "Parsana gym is very good sarvice provide . Nice team work",
"time" : 1527738686
}
],
"scope" : "GOOGLE",
"types" : [ "gym", "health", "point_of_interest", "establishment" ],
"url" : "https://maps.google.com/?cid=14275967968530345631",
"utc_offset" : 330,
"vicinity" : "3rd Floor, Sardar Patel Mall, Nikol Gam Road, Bapunagar, Ahmedabad"
},
"status" : "OK"
}
I use volley that gives parse exception.
Here is my code
I am trying to parse JSON format using volley using below code.
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(url, new Response.Listener<JSONArray>() {
#Override
public void onResponse(JSONArray response) {
for (int i = 0; i < response.length(); i++) {
try {
JSONObject object = response.getJSONObject(i);
JSONObject result = object.getJSONObject("result");
JSONArray array = result.getJSONArray("address_components");
Log.d("result", "" + array.length());
for (int adress = 0; adress < array.length(); adress++) {
JSONObject object1 = array.getJSONObject(i);
Log.d("result", object1.getString("long_name"));
Log.d("result", object1.getString("short_name"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
//Error lisnter for request
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d("error", error.getMessage());
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonArrayRequest );
Can Anyone help what I am missing in this?
here is exception.
Note-: org.json.JSONException: Value {"html_attributions":[],"result":{"address_components":[{"long_name":"Ahmedabad","short_name":"Ahmedabad","t.........}
Thanks in advance !!
Do this :
your response starts with jsonObject'{' not jsonArray'['
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(url, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
JSONObject jsonObject = response.getJSONObject("result");
JSONArray jsonArray = jsonObject.getJSONArray("address_components");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
Log.d("result", object.getString("long_name"));
Log.d("result", object.getString("short_name"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
//Error lisnter for request
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d("error", error.getMessage());
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonArrayRequest );
I'm using Android Volley to fetch JSON objects from an API. I'm going to use this URL as a reference: https://glosbe.com/gapi/translate?from=la&dest=eng&format=json&phrase=puer&pretty=true
Basically, I'm trying to convert between Latin and English using this API. I'm having an issue where, when I fetch the JSON in my app, and display it using toString(), it doesn't show some content that I was able to see if I pulled it up in my browser. Here's what it looked like in my browser:
{
"result" : "ok",
"tuc" : [ {
"phrase" : {
"text" : "boy",
"language" : "en"
},
"meanings" : [ {
"language" : "en",
"text" : "male servant"
}, {
"language" : "en",
"text" : "young male"
}, {
"language" : "en",
"text" : "youth (1)"
} ],
"meaningId" : 5190805061708394514,
"authors" : [ 89651 ]
}, {
"phrase" : {
"text" : "child",
"language" : "en"
},
"meanings" : [ {
"language" : "en",
"text" : "a minor"
} ],
"meaningId" : -7607542873189716522,
"authors" : [ 89651 ]
}, {
"phrase" : {
"text" : "lad",
"language" : "en"
},
"meaningId" : -4906708417289394649,
"authors" : [ 66257 ]
}, {
"phrase" : {
"text" : "young",
"language" : "en"
},
"meanings" : [ {
"language" : "en",
"text" : "in the early part of life or growth"
} ],
"meaningId" : -3502972425310277951,
"authors" : [ 83058 ]
}, {
"phrase" : {
"text" : "laddie",
"language" : "en"
},
"meaningId" : 8881496802632467440,
"authors" : [ 36 ]
}, {
"phrase" : {
"text" : "son",
"language" : "en"
},
"meaningId" : -5777550766434985278,
"authors" : [ 25115 ]
}, {
"phrase" : {
"text" : "teenager",
"language" : "en"
},
"meanings" : [ {
"language" : "en",
"text" : "person aged between thirteen and nineteen"
} ],
"meaningId" : 3903113562290975250,
"authors" : [ 83058 ]
}, {
"phrase" : {
"text" : "young man",
"language" : "en"
},
"meaningId" : 8100655201654223005,
"authors" : [ 1490 ]
}, {
"phrase" : {
"text" : "youth",
"language" : "en"
},
"meanings" : [ {
"language" : "en",
"text" : "youth (1)"
} ],
"meaningId" : 3228296648002997345,
"authors" : [ 92945 ]
}, {
"phrase" : {
"text" : "attendant",
"language" : "en"
},
"meaningId" : -215343938140795468,
"authors" : [ 66257 ]
}, {
"phrase" : {
"text" : "children",
"language" : "en"
},
"meaningId" : -7262823696521965327,
"authors" : [ 66257 ]
}, {
"phrase" : {
"text" : "kid",
"language" : "en"
},
"meaningId" : 667611545945379095,
"authors" : [ 13 ]
}, {
"phrase" : {
"text" : "little son",
"language" : "en"
},
"meaningId" : 7069478616059810263,
"authors" : [ 66257 ]
}, {
"phrase" : {
"text" : "male child",
"language" : "en"
},
"meaningId" : -6364965082259980533,
"authors" : [ 66257 ]
}, {
"phrase" : {
"text" : "servant",
"language" : "en"
},
"meaningId" : 3306664352577272579,
"authors" : [ 66257 ]
}, {
"phrase" : {
"text" : "slave",
"language" : "en"
},
"meaningId" : 3485776351359445593,
"authors" : [ 66257 ]
}, {
"meanings" : [ {
"language" : "en",
"text" : "(in the plural) children"
}, {
"language" : "en",
"text" : "boyhood (ex: <i>in puero</i>, "in his boyhood" or "as a boy")"
}, {
"language" : "en",
"text" : "a child"
}, {
"language" : "en",
"text" : "a boy"
}, {
"language" : "en",
"text" : "a male servant"
}, {
"language" : "en",
"text" : "a bachelor"
}, {
"language" : "en",
"text" : "vocative singular of puer"
} ],
"meaningId" : -1803685626071521178,
"authors" : [ 1 ]
} ],
"phrase" : "puer",
"from" : "la",
"dest" : "en",
"authors" : {
"66257" : {
"U" : "",
"id" : 66257,
"N" : "Charlton T. Lewis",
"url" : "https://glosbe.com/source/66257"
},
"92945" : {
"U" : "",
"id" : 92945,
"N" : "CLLD Concepticon",
"url" : "https://glosbe.com/source/92945"
},
"1" : {
"U" : "http://en.wiktionary.org",
"id" : 1,
"N" : "en.wiktionary.org",
"url" : "https://glosbe.com/source/1"
},
"89651" : {
"U" : "",
"id" : 89651,
"N" : "GlosbeWordalignmentRnD",
"url" : "https://glosbe.com/source/89651"
},
"1490" : {
"U" : "http://www.archives.nd.edu/cgi-bin/words.exe",
"id" : 1490,
"N" : "Piotr Szelma",
"url" : "https://glosbe.com/source/1490"
},
"83058" : {
"U" : "",
"id" : 83058,
"N" : "Dbnary: Wiktionary as Linguistic Linked Open Data",
"url" : "https://glosbe.com/source/83058"
},
"36" : {
"U" : "http://freedict.org",
"id" : 36,
"N" : "freedict.org",
"url" : "https://glosbe.com/source/36"
},
"25115" : {
"U" : "",
"id" : 25115,
"N" : "GlTrav3",
"url" : "https://glosbe.com/source/25115"
},
"13" : {
"U" : "http://ro.wiktionary.org",
"id" : 13,
"N" : "ro.wiktionary.org",
"url" : "https://glosbe.com/source/13"
}
}
}
When I pull it up in my app, it doesn't show the "phrase" portion. Here's the code that I used:
RequestQueue mRequestQueue;
Cache cache = new DiskBasedCache(getActivity().getCacheDir(), 1024 * 1024); // 1MB cap
Network network = new BasicNetwork(new HurlStack());
mRequestQueue = new RequestQueue(cache, network);
mRequestQueue.start();
String url = "https://glosbe.com/gapi/translate?from=la&dest=eng&format=json&phrase=" + e.getText().toString();
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest
(Request.Method.GET, url, null, new Response.Listener<JSONObject>()
{
#Override
public void onResponse(JSONObject response)
{
Log.d("JSON", response.toString());
try
{
JSONArray arr = response.getJSONArray("tuc");
try
{
JSONObject phrase = response.getJSONObject("phrase");
}
catch(JSONException e)
{
Toast.makeText(getActivity(), "Phrase not found", Toast.LENGTH_LONG).show();
}
Log.d("JSON", arr.toString());
try
{
JSONArray arr2 = arr.getJSONObject(0).getJSONArray("meanings");
definition = arr2.getJSONObject(0).getString("text");
t.setText(definition);
Toast.makeText(getActivity(), "Got stuff sucessfully", Toast.LENGTH_LONG).show();
}
catch (JSONException e)
{
JSONObject phrase = arr.getJSONObject(0);
definition = phrase.getString("text");
t.setText(definition);
Toast.makeText(getActivity(), "Got stuff succesfully with exception", Toast.LENGTH_LONG).show();
}
}
catch(JSONException e)
{
Log.d("error", e.toString());
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error)
{
Log.d("Error", error.toString());
}
});
MySingleton.getInstance(getActivity()).addToRequestQueue(jsonObjectRequest);
The code you're using to parse it doesn't match the structure of the JSON.
"tuc" is an array, "phrase" and "meanings" are inside the objects in that array. Let's say you wanted to get just the first phrase:
JSONArray tuc = response.getJSONArray("tuc");
JSONObject phrase = tuc.getJSONObject(0).getJSONObject("phrase");
I think that's right but I don't have an Android project set up to test it at the moment.
Ok here is the code to parse your response in android:
try
{
JSONArray TUCarray = response.getJSONArray("tuc");
JsonObject phraseobject=TUCarray.getJSONObject(0).getJSONObject("phrase");
}
catch(JSONException e)
{
Toast.makeText(getActivity(), "Phrase not found",Toast.LENGTH_LONG).show();
}
Be careful when you are parsing the whole response because I could see that some objects of TUC array doesnt have sub object phrase eg:- Last object of the TUC array in the response of link you provided).
i am getting some paring error while running this code but i can not tell what is the problem .there is no error in the android studio syntax but there is a problem in the json parsing or with my Json as i am not able to understand how to call json object inside another json object and json arrays
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.ImageView;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.Gson;
import org.json.JSONObject;
public class BookFragment extends Fragment {
OneRestaurantBean restaurentinfo;
String placid="ChIJO3JIy9iDGjkRIekztZhsmGg";
PhotosBean photolist;
ReviewBean reviewlist;
StringRequest stringRequest;
Spinner table_for;
PhotosBean photolist;
ReviewBean reviewlist;
private String format = "";
TextView date,time;
int day,month,year,hour,minute;
String url="https://maps.googleapis.com/maps/api/place/details/json?placeid="+placeid+"&key=AIzaSyDGtQbIzeOGRk0kGq3rCy3xAvo1xVNB304";
TextView txtaddress,txtphone,txttiming;
ImageView image1,image2,image3;
// Executes the Request
RequestQueue requestQueue;
ProgressDialog pd;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_book, container, false);
requestQueue = Volley.newRequestQueue(getActivity());
table_for=(Spinner)view.findViewById(R.id.spinner);
date=(TextView)view.findViewById(R.id.textViewdate) ;
// timePicker1=(TimePicker)view.findViewById(R.id.timePicker2);
time=(TextView)view.findViewById(R.id.textviewtime);
txtaddress=(TextView)view.findViewById(R.id.textViewaddress);
txtphone=(TextView)view.findViewById(R.id.textViewphone);
txttiming=(TextView)view.findViewById(R.id.textViewTiming);
image1=(ImageView)view.findViewById(R.id.imageView2);
image2=(ImageView)view.findViewById(R.id.imageView3);
image3=(ImageView)view.findViewById(R.id.imageView4);
init();
getRestaurentsinfo();
return view;
}
private void init() {
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(),
R.array.Table_for, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
table_for.setAdapter(adapter);
}
private void getRestaurentsinfo() {
stringRequest = new StringRequest(com.android.volley.Request.Method.GET, url,
new com.android.volley.Response.Listener<String>() {
#Override
public void onResponse(String s) {
// pd.dismiss();
try {
JSONObject jsonObject = new JSONObject(s);
Gson gson = new Gson();
restaurentinfo = gson.fromJson(jsonObject.toString(), OneRestaurantBean.class);
Type listType = new TypeToken<List<PhotosBean>>(){}.getType();
photolist = (PhotosBean) gson.fromJson(jsonObject.toString(), listType);
Type listType2 = new TypeToken<List<ReviewBean>>(){}.getType();
reviewlist = (ReviewBean) gson.fromJson(jsonObject.toString(), listType2);
txtaddress.setText(restaurentinfo.getVicinity()); txttiming.setText(Arrays.toString(restaurentinfo.getOpenhour().getWeekday_text()).replaceAll("\\[|\\]", ""));
} catch (Exception e) {
Toast.makeText(getActivity(), "Some JSON Parsing Error", Toast.LENGTH_LONG).show();
}
}
},
// failure
new com.android.volley.Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(getActivity(), "Some Volley Error", Toast.LENGTH_LONG).show();
}
}
);
requestQueue.add(stringRequest);
}
my json file is as displayed below
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Ludhiana",
"short_name" : "Ludhiana",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Sarabha Nagar",
"short_name" : "Sarabha Nagar",
"types" : [ "sublocality_level_1", "sublocality", "political" ]
},
{
"long_name" : "Ludhiana",
"short_name" : "Ludhiana",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Punjab",
"short_name" : "PB",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "141003",
"short_name" : "141003",
"types" : [ "postal_code" ]
}
],
"adr_address" : "SCF-21, Sarabha Nagar Market, \u003cspan class=\"extended-address\"\u003eSarabha Nagar\u003c/span\u003e, \u003cspan class=\"locality\"\u003eLudhiana\u003c/span\u003e, \u003cspan class=\"region\"\u003ePunjab\u003c/span\u003e \u003cspan class=\"postal-code\"\u003e141003\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eIndia\u003c/span\u003e",
"formatted_address" : "SCF-21, Sarabha Nagar Market, Sarabha Nagar, Ludhiana, Punjab 141003, India",
"formatted_phone_number" : "0161 245 2810",
"geometry" : {
"location" : {
"lat" : 30.8927238,
"lng" : 75.8218431
}
},
"icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id" : "17865244baa6a88165cbe83f21d2713656bcece0",
"international_phone_number" : "+91 161 245 2810",
"name" : "Domino's Pizza",
"opening_hours" : {
"open_now" : false,
"periods" : [
{
"close" : {
"day" : 0,
"time" : "2300"
},
"open" : {
"day" : 0,
"time" : "1100"
}
},
{
"close" : {
"day" : 1,
"time" : "2300"
},
"open" : {
"day" : 1,
"time" : "1100"
}
},
{
"close" : {
"day" : 2,
"time" : "2300"
},
"open" : {
"day" : 2,
"time" : "1100"
}
},
{
"close" : {
"day" : 3,
"time" : "2300"
},
"open" : {
"day" : 3,
"time" : "1100"
}
},
{
"close" : {
"day" : 4,
"time" : "2300"
},
"open" : {
"day" : 4,
"time" : "1100"
}
},
{
"close" : {
"day" : 5,
"time" : "2300"
},
"open" : {
"day" : 5,
"time" : "1100"
}
},
{
"close" : {
"day" : 6,
"time" : "2300"
},
"open" : {
"day" : 6,
"time" : "1100"
}
}
],
"weekday_text" : [
"Monday: 11:00 AM – 11:00 PM",
"Tuesday: 11:00 AM – 11:00 PM",
"Wednesday: 11:00 AM – 11:00 PM",
"Thursday: 11:00 AM – 11:00 PM",
"Friday: 11:00 AM – 11:00 PM",
"Saturday: 11:00 AM – 11:00 PM",
"Sunday: 11:00 AM – 11:00 PM"
]
},
"photos" : [
{
"height" : 1836,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/102359458524790058006/photos\"\u003eKAMALJEET SINGH RANDHAWA\u003c/a\u003e"
],
"photo_reference" : "CoQBdwAAAIhIrZLQ_Z3H9UUm8Hu96z7N5L4HdKPd_IJbGNEfzW_v2c6zNe3bSYoz3Ya2XkoBHM_9bXBmKbw72d8N_vmFPyT14uqWCHz_WuLWGp_K0Ss-u7VCghzyUpVZ1F5-asNOeTCNLOwjre0FdO8rQsgb4slyJhMGgJg8Okogx_jlShuLEhDdW69Zmuh-aB-SCdI0XdFDGhT4zjH4vKwmgNYkWdcnY53bwD4eaA",
"width" : 3264
},
{
"height" : 600,
"html_attributions" : [
"\u003ca href=\"https://maps.google.com/maps/contrib/109327830988106108854/photos\"\u003eNirwal Karm\u003c/a\u003e"
],
"photo_reference" : "CoQBdwAAAPpyo99c8N-lt7F-l3YA7qSK7mZKY8zIyaMUoV3OqgOJ9DXVqspqpMQwIvu7KDycvrWcHpy6jaCpc2UyDm3SqtYhw2Fsr5IfgKjKbRTjDF-ST5a9w1vNs44O3SbHWwSLuKV6fhyax1xfqc2TEM7XqAE3K2XSOg5XCzgD8Nef3NJuEhAhTK3UI_yW-dim4bXP4ZK0GhQCO7kgf4E1f53t-_Tf4DEsjYF5xw",
"width" : 800
}
],
"place_id" : "ChIJAQAAwM2DGjkR6gVuwpeWwKk",
"price_level" : 1,
"rating" : 4.1,
"reference" : "CmRSAAAATiwel1VKVuyHEFkgl2LEMsL_Rxf9xV3EXj_N_o59Q0ZWGgy-XRjCTmFAPK6z1xRof9WpAKu9FTu-XaNyx6zxGlnzXVNRf-KUOjw-xBB5YdrdDN1VW7eN3E-qw6-pKdXREhCr9EeBMjBidk_KW74s9S9aGhS4NLG4UNMqWveymd0sBkpcieyybg",
"reviews" : [
{
"aspects" : [
{
"rating" : 2,
"type" : "overall"
}
],
"author_name" : "Vardaan Sharma",
"author_url" : "https://plus.google.com/116622040002550992578",
"language" : "en",
"profile_photo_url" : "//lh4.googleusercontent.com/-oc3UC8zHbqE/AAAAAAAAAAI/AAAAAAAACDE/eD2qok-jrMQ/photo.jpg",
"rating" : 4,
"text" : "Love The Garlic Bread!! Awesome Taste for Decent Prices!!!",
"time" : 1465754538
},
{
"aspects" : [
{
"rating" : 0,
"type" : "overall"
}
],
"author_name" : "Darleen Grewal",
"author_url" : "https://plus.google.com/102174339060680368258",
"language" : "en",
"rating" : 1,
"text" : "Pathetic delivery service , orders delayed by one and a half hour and staff is uneducated and non Cooperating",
"time" : 1476727634
},
{
"aspects" : [
{
"rating" : 2,
"type" : "overall"
}
],
"author_name" : "Abhishek Attri",
"author_url" : "https://plus.google.com/103724862705815258945",
"language" : "en",
"profile_photo_url" : "//lh6.googleusercontent.com/-8XVYso4qYxc/AAAAAAAAAAI/AAAAAAAAHIA/63UVRnCpc8M/photo.jpg",
"rating" : 4,
"text" : "Nice place.. ",
"time" : 1478198571
},
{
"aspects" : [
{
"rating" : 0,
"type" : "overall"
}
],
"author_name" : "Bhavesh Bansal",
"author_url" : "https://plus.google.com/107902290149968294793",
"language" : "en",
"profile_photo_url" : "//lh5.googleusercontent.com/-0GAn_nkPa9g/AAAAAAAAAAI/AAAAAAAAAro/1Z2WU1Tup7g/photo.jpg",
"rating" : 1,
"text" : "Poor service. Last 2 orders have been delayed by almost 2 hours. All their contact numbers are unreachable or busy, when you try to contact them.\nSeems like they dont care anymore about customer",
"time" : 1463848060
},
{
"aspects" : [
{
"rating" : 0,
"type" : "overall"
}
],
"author_name" : "Gurmeet Gujral",
"author_url" : "https://plus.google.com/113150303121450342768",
"language" : "en",
"profile_photo_url" : "//lh3.googleusercontent.com/-zzCCjI2B4HU/AAAAAAAAAAI/AAAAAAAAJ0w/JOBa4Aetq3E/photo.jpg",
"rating" : 1,
"text" : "Don't call them for home delivery. They will serve you cold",
"time" : 1439473587
}
],
"scope" : "GOOGLE",
"types" : [
"meal_delivery",
"meal_takeaway",
"restaurant",
"food",
"point_of_interest",
"establishment"
],
"url" : "https://maps.google.com/?cid=12231942166484485610",
"utc_offset" : 330,
"vicinity" : "SCF-21, Sarabha Nagar Market, Ludhiana",
"website" : "http://www.dominos.co.in/"
},
"status" : "OK"
}
I found error in json parsing,use some other parsing method such as
Retrofit . Volley JSON Parsing Sample Example
http://www.androidhive.info/2014/09/android-json-parsing-using-volley/
Heyy guyz I am receiving JSON using google places details api then In that Json I am looking for "reviews" array.But in logcat I am getting system error that No values for reviews.But I checked in Json that there exist reviews array.Where is the problem?Thanx in advance.This is my JSON data:
{
"result" : {
"address_components" : [
{
"long_name" : "Kalyan",
"short_name" : "Kalyan",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Maharashtra",
"short_name" : "Maharashtra",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "India",
"short_name" : "IN",
"types" : [ "country", "political" ]
},
{
"long_name" : "421301",
"short_name" : "421301",
"types" : [ "postal_code" ]
}
],
"reviews" : [
{
"aspects" : [
{
"rating" : 0,
"type" : "overall"
}
],
"author_name" : "Kunal Korde",
"author_url" : "https://plus.google.com/108837578005055609416",
"language" : "en",
"rating" : 1,
"text" : "it is very bad to call domino one and only kalyan
"time" : 1382351314
},
{
"aspects" : [
{
"rating" : 3,
"type" : "food"
},
{
"rating" : 2,
"type" : "decor"
},
{
"rating" : 1,
"type" : "service"
}
],
"author_name" : "Hits Daiya",
"author_url" : "https://plus.google.com/101565870698816750539",
"language" : "en",
"rating" : 4,
"text" : "wt a excellent food anybody can get here! I wanna to say that wt a
"time" : 1371385367
},
{
"aspects" : [
{
"rating" : 1,
"type" : "overall"
}
],
"author_name" : "nirmit jallawar",
"author_url" : "https://plus.google.com/116255076196839398528",
"language" : "en",
"rating" : 3,
"text" : "Good but a bit more of standard is necessary ",
"time" : 1402139860
},
{
"aspects" : [
{
"rating" : 2,
"type" : "food"
},
{
"rating" : 0,
"type" : "decor"
},
{
"rating" : 1,
"type" : "service"
}
],
"author_name" : "Rutam Mokashi",
"author_url" : "https://plus.google.com/112151348544733227698",
"language" : "en",
"rating" : 3,
"text" : "best place for pizzas in kalyan...",
"time" : 1353151680
},
{
"aspects" : [
{
"rating" : 1,
"type" : "food"
},
{
"rating" : 2,
"type" : "decor"
},
{
"rating" : 2,
"type" : "service"
}
],
"author_name" : "A.A Varghese varghese",
"author_url" : "https://plus.google.com/103110235851606786394",
"language" : "en",
"rating" : 4,
"text" : "nice hotel.",
"time" : 1375596316
}
],
"scope" : "GOOGLE",
"types" : [ "restaurant", "food", "establishment" ],
"url" : "https://plus.google.com/107013844902194125587/about?hl=en-US",
"user_ratings_total" : 32,
"utc_offset" : 330,
"vicinity" : "Plot No. C 1, Ground Floor, Shop No. 2, 3 & 4, Chikanghar, Kalyan",
"website" : "http://www.dominos.co.in/"
},
"status" : "OK"
}
and this my code:
public class Review_activity extends ActivityGroup {
protected static LocalActivityManager mLocalActivityManager;
// Alert Dialog Manager
AlertDialogManager alert = new AlertDialogManager();
ProgressDialog pDialog;
JSONObject json = null;
// Review Listview
ListView list;
String reference;
public static final String TAG_name = "-NA-";
public static final String TAG_rating = "-NA-";
public static final String TAG_text = "-NA-";
public static String reference_value = "reference";
public static String KEY_REFERENCE = "reference";// id of the place
private static final String TEL_PREFIX = "tel:";
ArrayList<HashMap<String, String>> oslist = newArrayList<HashMap<String,String>>();
// public static String url = "";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.review);
oslist = new ArrayList<HashMap<String, String>>();
// Getting listview
list = (ListView) findViewById(R.id.list);
// Getting place reference from the map
reference = getIntent().getStringExtra("reference");
Log.d("yogesh", reference);
String sb ="https://maps.googleapis.com/maps/api/place/details/json?";
String sb1=sb.concat("&reference="+reference);
String sb2=sb1.concat("&sensor=true");
String sb3=sb2.concat("&key=AIzaSyChVcy-8fLkAq5-ZJCuNomF1lIf-Gda7s8");
String url=sb3;
Log.d("URL", url);
new JSONParse().execute(url);
}
private class JSONParse extends AsyncTask<String, String, JSONObject> {
#Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(Review_activity.this);
pDialog.setMessage("Getting Reviews ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
#Override
protected JSONObject doInBackground(String... params) {
JSONParser jParser = new JSONParser();
// Getting JSON from URL
String s = params[0];
Log.d("URL", s);
JSONObject json = jParser.getJSONFromUrl(s);
return json;
}
#Override
protected void onPostExecute(JSONObject json) {
pDialog.dismiss();
try {
// Getting JSON Array from URL
JSONArray jArray = json.getJSONArray("reviews");
int k;
k=jArray.length();
k--;
String Alength=String.valueOf(k);
Log.d("Array length", Alength);
//To get the items from the array
int j=0;
for (int i=0;i<=k;i++)
{
JSONObject r1 = jArray.getJSONObject(j);
String aname = r1.getString("author_name");
String arating = r1.getString("rating");
String text = r1.getString("text");
Log.d("review", aname);
Log.d("review", arating);
Log.d("review", text);
j++;
// Adding value HashMap key => value
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_name, aname);
map.put(TAG_rating, arating);
map.put(TAG_text,text );
oslist.add(map);
}
list=(ListView)findViewById(R.id.list);
ListAdapter adapter = new SimpleAdapter(Review_activity.this, oslist,
R.layout.review_item,
new String[] { TAG_name,TAG_rating, TAG_text }, new int[] {
R.id.textView2,R.id.textView4, R.id.textView6});
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
i found your json is not a valid json
use check if json is valid or not this to check valid json
i correct it and the valid json is here
{
"result": {
"address_components": [
{
"long_name": "Kalyan",
"short_name": "Kalyan",
"types": [
"locality",
"political"
]
},
{
"long_name": "Maharashtra",
"short_name": "Maharashtra",
"types": [
"administrative_area_level_1",
"political"
]
},
{
"long_name": "India",
"short_name": "IN",
"types": [
"country",
"political"
]
},
{
"long_name": "421301",
"short_name": "421301",
"types": [
"postal_code"
]
}
],
"reviews": [
{
"aspects": [
{
"rating": 0,
"type": "overall"
}
],
"author_name": "Kunal Korde",
"author_url": "https://plus.google.com/108837578005055609416",
"language": "en",
"rating": 1,
"text": "it is very bad to call domino one and only kalyan",
"time": 1382351314
},
{
"aspects": [
{
"rating": 3,
"type": "food"
},
{
"rating": 2,
"type": "decor"
},
{
"rating": 1,
"type": "service"
}
],
"author_name": "HitsDaiya",
"author_url": "https: //plus.google.com/101565870698816750539",
"language": "en",
"rating": 4,
"text": "wtaexcellentfoodanybodycangethere!Iwannatosaythatwta",
"time": 1371385367
},
{
"aspects": [
{
"rating": 1,
"type": "overall"
}
],
"author_name": "nirmitjallawar",
"author_url": "https: //plus.google.com/116255076196839398528",
"language": "en",
"rating": 3,
"text": "Goodbutabitmoreofstandardisnecessary",
"time": 1402139860
},
{
"aspects": [
{
"rating": 2,
"type": "food"
},
{
"rating": 0,
"type": "decor"
},
{
"rating": 1,
"type": "service"
}
],
"author_name": "RutamMokashi",
"author_url": "https: //plus.google.com/112151348544733227698",
"language": "en",
"rating": 3,
"text": "bestplaceforpizzasinkalyan...",
"time": 1353151680
},
{
"aspects": [
{
"rating": 1,
"type": "food"
},
{
"rating": 2,
"type": "decor"
},
{
"rating": 2,
"type": "service"
}
],
"author_name": "A.AVarghesevarghese",
"author_url": "https: //plus.google.com/103110235851606786394",
"language": "en",
"rating": 4,
"text": "nicehotel.",
"time": 1375596316
}
],
"scope": "GOOGLE",
"types": [
"restaurant",
"food",
"establishment"
],
"url": "https: //plus.google.com/107013844902194125587/about?hl=en-US",
"user_ratings_total": 32,
"utc_offset": 330,
"vicinity": "PlotNo C1 GroundFloor ShopNo 2 3 4 Chikanghar Kalyan",
"website": "http: //www.dominos.co.in/"
},
"status": "OK"
}
i found your code seems pretty correct ....
the safer side is first print the response json and check if its valid or not....
Issue is you first to get json object for "result" then use that object to find json array for review.
jsonobject = json.getJsonObject("result");
resultArray = jsonobject.getJsonArray("review");
{
"TABLE":[
{
"ROW":[
{
"COL":[
{
"DATA":"< OutBoundSMS PhoneId='3' PhoneNo='1111111111' MessageText='OutBound SMS Application Test' />"
}
]
}
]
}
]
}
How to parse json array like this format?
I am getting this error while parsing: "cannot be converted to json object".
Parse Current Json String as:
JSONObject json=new JSONObject("Your Json String");
JSONArray jsonarray = json.getJSONArray("TABLE");
for(int i=0;i<jsonarray.length();i++){
JSONObject jsonnew=jsonarray.getJSONObject(i);
JSONArray jsonarrayROW = jsonnew.getJSONArray("ROW");
for(int j=0;j<jsonarrayROW.length();j++){
JSONObject jsonnewtwo=jsonarrayROW.getJSONObject(j);
JSONArray jsonarrayCOL = jsonnewtwo.getJSONArray("COL");
for(int k=0;k<jsonarrayCOL.length();k++){
JSONObject jsonnewthree=jsonarrayCOL.getJSONObject(k);
//get DATA here
String str_data=jsonnewthree.getString("DATA");
}
}
}
see here
String jsonStr = '{"menu": {' +
'"id": "file",' +
'"value": "File",' +
'"popup": {' +
'"menuitem": [' +
'{"value": "New", "onclick": "CreateNewDoc()"},' +
'{"value": "Open", "onclick": "OpenDoc()"},' +
'{"value": "Close", "onclick": "CloseDoc()"}' +
']' +
'}' +
'}}';
here see good example JSON PARSING
Its Working parse json data array inside array
http://maps.googleapis.com/maps/api/directions/json?origin=28.4759618,77.3140897&destination=28.3936072,77.3172154&sensor=false&mode=driving&alternatives=true
{
"geocoded_waypoints" : [
{
"geocoder_status" : "OK",
"place_id" : "ChIJzfXobhTnDDkRJQ2M4AEkun8",
"types" : [ "street_address" ]
},
{
"geocoder_status" : "OK",
"place_id" : "ChIJrz2dDk_cDDkRmnC23K0BpD4",
"types" : [ "street_address" ]
}
],
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : 28.4808871,
"lng" : 77.3195229
},
"southwest" : {
"lat" : 28.3932808,
"lng" : 77.30536649999999
}
},
"copyrights" : "Map data ©2017 Google",
"legs" : [
{
"distance" : {
"text" : "11.9 km",
"value" : 11902
},
"duration" : {
"text" : "22 mins",
"value" : 1313
},
"end_address" : "384, Sector-16, Sector 15A, Faridabad, Haryana 121007, India",
"end_location" : {
"lat" : 28.3936165,
"lng" : 77.31753990000001
},
"start_address" : "A-105, Ashoka Enclave Part II, Sector 37, Faridabad, Haryana 121003, India",
"start_location" : {
"lat" : 28.4759614,
"lng" : 77.3139839
},
"steps" : [
{
"distance" : {
"text" : "14 m",
"value" : 14
},
"duration" : {
"text" : "1 min",
"value" : 3
},
"end_location" : {
"lat" : 28.4760899,
"lng" : 77.31398329999999
},
"html_instructions" : "Head \u003cb\u003enorth\u003c/b\u003e",
"polyline" : {
"points" : "wuxlDkk{vMY?"
},
"start_location" : {
"lat" : 28.4759614,
"lng" : 77.3139839
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.4 km",
"value" : 440
},
"duration" : {
"text" : "2 mins",
"value" : 116
},
"end_location" : {
"lat" : 28.4766301,
"lng" : 77.3097228
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e toward \u003cb\u003eOld Sher Shah Suri Road\u003c/b\u003e/\u003cb\u003eSarai Khawaja Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "qvxlDkk{vMApB?Z?jB?bACvDAx#?T#v#?#Dx#?H?FADABCBw#bAQRY`#"
},
"start_location" : {
"lat" : 28.4760899,
"lng" : 77.31398329999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.5 km",
"value" : 503
},
"duration" : {
"text" : "1 min",
"value" : 81
},
"end_location" : {
"lat" : 28.4808871,
"lng" : 77.30797579999999
},
"html_instructions" : "Slight \u003cb\u003eright\u003c/b\u003e onto \u003cb\u003eOld Sher Shah Suri Road\u003c/b\u003e/\u003cb\u003eSarai Khawaja Rd\u003c/b\u003e",
"maneuver" : "turn-slight-right",
"polyline" : {
"points" : "}yxlDwpzvMIDiF|AcBh#{Bp#eGhByBp#"
},
"start_location" : {
"lat" : 28.4766301,
"lng" : 77.3097228
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.3 km",
"value" : 255
},
"duration" : {
"text" : "1 min",
"value" : 50
},
"end_location" : {
"lat" : 28.4808239,
"lng" : 77.30536649999999
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eMain Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "qtylD{ezvMHnEBxH"
},
"start_location" : {
"lat" : 28.4808871,
"lng" : 77.30797579999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "1.0 km",
"value" : 1013
},
"duration" : {
"text" : "2 mins",
"value" : 125
},
"end_location" : {
"lat" : 28.4717998,
"lng" : 77.30594619999999
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eNH19\u003c/b\u003e/\u003cb\u003eNH44\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Hotel Saffron Kiran (on the left in 1.0 km)\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "ctylDquyvMhA?^An#?lAEfAGrEQzBMH?DALEJGzCw#TC`#C^AV?P?T#rALL?v#B\\?VAz#CjB#h#?X?fBG~#B^NrCKTA"
},
"start_location" : {
"lat" : 28.4808239,
"lng" : 77.30536649999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "7.5 km",
"value" : 7549
},
"duration" : {
"text" : "10 mins",
"value" : 624
},
"end_location" : {
"lat" : 28.4041209,
"lng" : 77.3116127
},
"html_instructions" : "Keep \u003cb\u003eright\u003c/b\u003e to stay on \u003cb\u003eNH19\u003c/b\u003e/\u003cb\u003eNH44\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Bank Of India (on the left in 2.4 km)\u003c/div\u003e",
"maneuver" : "keep-right",
"polyline" : {
"points" : "w{wlDeyyvM|HU`DMrAEnQu#jASVCXEpGUfDM`BGl#ED?z#CrAGpAEdBI^AfF[~DSvLa#xJ_#lFSvEQlHQlIa#zHUnIa#~FWbBItBGfDIbDMrAP|DMnCMxBEl#?`BGtBMhAG`H[d#AnEQZAxBGbBGfFSxBIpBI`GSfEOlCIVATAh#Ch#AzFWtQu#rHWd#C~J_#`FQl#A`#Ct#AnAE`#Cr#EhCI^A\\Al#El#Ch#ApCOxBI\\AnDOvBG|BIdESzGU|DMvAG`#CdDOnAE~CIf#ElAClDM"
},
"start_location" : {
"lat" : 28.4717998,
"lng" : 77.30594619999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "11 m",
"value" : 11
},
"duration" : {
"text" : "1 min",
"value" : 4
},
"end_location" : {
"lat" : 28.404129,
"lng" : 77.3117281
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eGovernment College Rd\u003c/b\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "wtjlDq|zvMAW"
},
"start_location" : {
"lat" : 28.4041209,
"lng" : 77.3116127
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.3 km",
"value" : 274
},
"duration" : {
"text" : "1 min",
"value" : 31
},
"end_location" : {
"lat" : 28.4016677,
"lng" : 77.31193089999999
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e toward \u003cb\u003eLal Bahadur Shastri Marg\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "ytjlDi}zvMz#CzBMz#Ah#ClEO"
},
"start_location" : {
"lat" : 28.404129,
"lng" : 77.3117281
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.7 km",
"value" : 677
},
"duration" : {
"text" : "2 mins",
"value" : 100
},
"end_location" : {
"lat" : 28.4018048,
"lng" : 77.318851
},
"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eLal Bahadur Shastri Marg\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Sun Flag Hospital & Research Centre (on the left in 650 m)\u003c/div\u003e",
"maneuver" : "turn-left",
"polyline" : {
"points" : "mejlDq~zvMA]?_A?sD?gD?yC?_F?q#EiDIwCCcBC{A"
},
"start_location" : {
"lat" : 28.4016677,
"lng" : 77.31193089999999
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.9 km",
"value" : 936
},
"duration" : {
"text" : "2 mins",
"value" : 126
},
"end_location" : {
"lat" : 28.3934097,
"lng" : 77.3195229
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e at \u003cb\u003eSector 16 Rd\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003ePass by Gymkhana Club - I (on the right)\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "gfjlDyi|vMnAGrNg#nBGtBInIUlDKdJa#"
},
"start_location" : {
"lat" : 28.4018048,
"lng" : 77.318851
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "0.2 km",
"value" : 193
},
"duration" : {
"text" : "1 min",
"value" : 41
},
"end_location" : {
"lat" : 28.3932808,
"lng" : 77.3175523
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "yqhlD_n|vMPrE#nADdB"
},
"start_location" : {
"lat" : 28.3934097,
"lng" : 77.3195229
},
"travel_mode" : "DRIVING"
},
{
"distance" : {
"text" : "37 m",
"value" : 37
},
"duration" : {
"text" : "1 min",
"value" : 12
},
"end_location" : {
"lat" : 28.3936165,
"lng" : 77.31753990000001
},
"html_instructions" : "Turn \u003cb\u003eright\u003c/b\u003e\u003cdiv style=\"font-size:0.9em\"\u003eDestination will be on the left\u003c/div\u003e",
"maneuver" : "turn-right",
"polyline" : {
"points" : "_qhlDua|vMcA#"
},
"start_location" : {
"lat" : 28.3932808,
"lng" : 77.3175523
},
"travel_mode" : "DRIVING"
}
],
"traffic_speed_entry" : [],
"via_waypoint" : []
}
],
"overview_polyline" : {
"points" : "wuxlDkk{vMY?ApB?fCEjIF|BGTiAvAY`#IDmIfCaKzCyBp#HnEBxHhA?nAAtCM~Ia#XMpD{#`AEh#?hBNdAB|ECbA?fBG~#B^NrCKrIWtFSnQu#jASp#IxLc#pEQjHYfLo#pXaAdMe#lHQlIa#zHUnIa#bJa#|GQbDMrAPlI[fDEvEUjJc#jK]fd#_BdJ_#h[mAdLc#fJYnHYlNk#jRu#rQo#tFUfEOzFQAWz#CvDOvFSAyL?yJE{EM{FC{AnAGbRo#dM_#lDKdJa#RbHDdBcA#"
},
"summary" : "NH19/NH44",
"warnings" : [],
"waypoint_order" : []
}
],
"status" : "OK"
}
Handle
import android.app.Dialog;
import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
private Dialog mDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callApiArrayInsideArray();
}
private void callApiArrayInsideArray() {
JSONObject jsonObject = new JSONObject();
// TODO Send parameter using this in volley apis
/*try {
jsonObject.put("UserId", "abc");
} catch (JSONException e) {
e.printStackTrace();
}*/
// String url = Constants.GetData;
String url = "http://maps.googleapis.com/maps/api/directions/json?origin=28.4759618,77.3140897&destination=28.3936072,77.3172154&sensor=false&mode=driving&alternatives=true";
mDialog = ProgressDialog.show(MainActivity.this, "", "Please wait", true);
mDialog.setCancelable(false);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url,
jsonObject, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.i("tag", "Volley response: " + response.toString());
if (mDialog != null) {
mDialog.dismiss();
}
// TODO when Success Response then set parse data in list view
parseResponse(response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
if (mDialog != null) {
mDialog.dismiss();
}
Log.i("tag", "Volley error: " + error.getMessage());
}
});
Volley.newRequestQueue(this).add(jsonObjectRequest);
}
private void parseResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("routes");
Log.e("MainActivity", "jsonArray --> " + jsonArray.toString(2));
if (jsonArray != null)
{
for (int i = 0; i < jsonArray.length(); i++)
{
JSONObject jsonnew = jsonArray.getJSONObject(i);
JSONArray jsonarrayROW = jsonnew.getJSONArray("legs");
for (int j = 0; j < jsonarrayROW.length(); j++)
{
JSONObject jsonnewtwo = jsonarrayROW.getJSONObject(j);
JSONArray jsonarrayCOL = jsonnewtwo.getJSONArray("steps");
for (int k = 0; k < jsonarrayCOL.length(); k++)
{
JSONObject jsonnewthree = jsonarrayCOL.getJSONObject(k);
String str_data = jsonnewthree.getString("html_instructions");
Log.e("Keshav", "html_instructions -> " + str_data);
}
}
Log.e("Keshav", "GeoEvent List->");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}