Capture & extract data from JSON

F

FP

<script type="text/javascript">
var abc = "http://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy,+Mountain+View,+CA+94043&sensor=false"
var def = json.parseJSON(abc);
document.write(def.geometry.location.lng);
</script>


If I enter the URL in the variable "abc" into the browser it downloads
a file called "json" containing amongst other things the GPS co-
ordinates for the location. I want my web page to just display the
longitude for that location.
What should the code be?
 
S

Seni Seven

FP said:
<script type="text/javascript">
var abc = "http://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy,+Mountain+View,+CA+94043&sensor=false"
var def = json.parseJSON(abc);
document.write(def.geometry.location.lng);
</script>


If I enter the URL in the variable "abc" into the browser it downloads
a file called "json" containing amongst other things the GPS co-
ordinates for the location. I want my web page to just display the
longitude for that location.
What should the code be?

The script shown should pretty much do it. You should be able to place the
block of text contained in the script element within the body element of the
HTML document.

You must also include the script that defines an object 'json' with the
method 'parseJSON()' that takes as its argument a string representing a URL
which is a JSON-formatted text file. Presumably you have a library that
defines that object and the required method and supporting code.
 
M

MC

FP said:
<script type="text/javascript">
var abc = "http://maps.googleapis.com/maps/api/geocode/json?
address=1600+Amphitheatre+Pkwy,+Mountain+View,+CA+94043&sensor=false"
var def = json.parseJSON(abc);
document.write(def.geometry.location.lng);
</script>


If I enter the URL in the variable "abc" into the browser it downloads
a file called "json" containing amongst other things the GPS co-
ordinates for the location. I want my web page to just display the
longitude for that location.
What should the code be?

I think what they are saying is that you will need to make this request on
the server, parse the response, and feed it to your browser via html, php,
jsp, asp etc.

Something like this in using Dojo and js:
var response = dojo.fromJson(xmlHttpResponse);
var lattitude = response.results.geometry.location.lat;
var longitude= response.results.geometry.location.lng;

MC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top