How to get data out of JSON object?

I'm using JSON.js provided in

<% JSONReturn = GetDistance(Sample) // return a string in JSON format (Arcgis server Solve route function) JSONObject = JSON.parse(JSONReturn,"Total_Length") %>

I'm trying to get the "total_length" data in the JSON object. May I know how can I retrieve it?

GetDistance Return this

{ "routes" : {"spatialReference" : { "wkid" : 4326 }, "features" : [ { "attributes" : { "ObjectID" : 1, "Name" : "Location 1 - Location 2", "FirstStopID" : 1, "LastStopID" : 2, "StopCount" : 2, "Total_Length" : 0.498263273388147, "Shape_Length" : 0 }, "geometry" : null } ] }, "messages" : [ ]


-------------Problems Reply------------

Try this.

<%@ Language=VBScript %>
<script language="JavaScript" runat="server">
Original file located at :
var json_parse=(function(){"use strict";var at,ch,escapee={'"':'"','\\':'\\','/':'/',b:'\b',f:'\f',n:'\n',r:'\r',t:'\t'},text,error=function(m){throw{name:'SyntaxError',message:m,at:at,text:text};},next=function(c){if(c&&c!==ch){error("Expected '"+c+"' instead of '"+ch+"'");}ch=text.charAt(at);at+=1;return ch;},number=function(){var number,string='';if(ch==='-'){string='-';next('-');}while(ch>='0'&&ch<='9'){string+=ch;next();}if(ch==='.'){string+='.';while(next()&&ch>='0'&&ch<='9'){string+=ch;}}if(ch==='e'||ch==='E'){string+=ch;next();if(ch==='-'||ch==='+'){string+=ch;next();}while(ch>='0'&&ch<='9'){string+=ch;next();}}number=+string;if(!isFinite(number)){error("Bad number");}else{return number;}},string=function(){var hex,i,string='',uffff;if(ch==='"'){while(next()){if(ch==='"'){next();return string;}else if(ch==='\\'){next();if(ch==='u'){uffff=0;for(i=0;i<4;i+=1){hex=parseInt(next(),16);if(!isFinite(hex)){break;}uffff=uffff*16+hex;}string+=String.fromCharCode(uffff);}else if(typeof escapee[ch]==='string'){string+=escapee[ch];}else{break;}}else{string+=ch;}}}error("Bad string");},white=function(){while(ch&&ch<=' '){next();}},word=function(){switch(ch){case't':next('t');next('r');next('u');next('e');return true;case'f':next('f');next('a');next('l');next('s');next('e');return false;case'n':next('n');next('u');next('l');next('l');return null;}error("Unexpected '"+ch+"'");},value,array=function(){var array=[];if(ch==='['){next('[');white();if(ch===']'){next(']');return array;}while(ch){array.push(value());white();if(ch===']'){next(']');return array;}next(',');white();}}error("Bad array");},object=function(){var key,object={};if(ch==='{'){next('{');white();if(ch==='}'){next('}');return object;}while(ch){key=string();white();next(':');if(,key)){error('Duplicate key "'+key+'"');}object[key]=value();white();if(ch==='}'){next('}');return object;}next(',');white();}}error("Bad object");};value=function(){white();switch(ch){case'{':return object();case'[':return array();case'"':return string();case'-':return number();default:return ch>='0'&&ch<='9'?number():word();}};return function(source,reviver){var result;text=source;at=0;ch=' ';result=value();white();if(ch){error("Syntax error");}return typeof reviver==='function'?(function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}return,key,value);}({'':result},'')):result;};}());
'JSONReturn = GetDistance(Sample) // return a string in JSON format (Arcgis server Solve route function)
Dim JSONReturn, JSONObject
JSONReturn = "{""TotalLength"" : 123}" 'Test
Set JSONObject = json_parse(JSONReturn)
Response.Write(JSONObject.TotalLength) 'Prints "123"
Set JSONObject = Nothing

You can access the properties of a JSON object by separating them by dots. Like any other object.

In your case JSONObject.routes.features[0].attributes.Total_Length

features[0] means the first element of the array, but you may have to loop on it.

Category:javascript Views:1 Time:2011-09-04

Related post

  • How to get data from a JSON object? 2011-08-27

    I'm trying to retrieve data from a JSON object that looks like this: stdClass Object ( [query] => stdClass Object ( [results] => stdClass Object ( [quote] => Array ( [0] => stdClass Object ( [foo] => bar ) [1] => stdClass Object ( [

  • Javascript. Access data in a JSON object (parsed). Please help! 2011-04-16

    I need to get the data "messages" from this JSON object. How can I do it in Javascript? To access for example the lastname I just use: response[i].user.lastname But how can I access the messages? [ { "user": { "last_message": { "message": { "created_

  • jquery sending form data and a json object in an ajax call 2011-05-09

    i'm making a call to another ajax page, the call posts a json object i also need to send data from a form (not using submit - i have the ajax call attached to a button which uses e.preventDeault()) the call is as folows: var myUrl = 'sendswatch-data.

  • Deleting particular data from a json object using JavaScript 2011-10-08

    I am using titanium for developing Android application. I want to delete some data from json object. My json object given below: {"feeds": [ {"username":"abc","user":"abc","feed":{"description":"dss","id":660,"user_id":1}}, {"username":"bcd","user":"

  • How to convert a string data to a JSON object in python? 2012-01-05

    Here is the sample string i am receiving from one of the web services,

  • Unable to get specific data from a JSON object 2013-10-29

    I am trying to extract specific data from a json response using org.json.JSONObject library Heres is my json response : { "facets": { "application": [ { "name": "38", "distribution": 1 } ], "node": [ { "name": "frstlwardu03_05", "distribution": 1 } ]

  • convert a HTML table data into a JSON object in jQuery 2010-02-10

    Anyone know how to convert an HTML table of values into a nice JSON object to be manipulated with jquery? --------------Solutions------------- An HTML table? Like, all the <td> contents in a 2-d array? var tbl = $('table#whatever tr').map(funct

  • How to add data dynamically in JSON object 2012-02-03

    Sample code var mydata = [ {id:"1",invdate:"2007-10-01",name:"test",note:"note",amount:"200.00",tax:"10.00",total:"210.00"}, {id:"2",invdate:"2007-10-02",name:"test2",note:"note2",amount:"300.00",tax:"20.00",total:"320.00"}]; I have to get output som

  • retrieve the data from Json object 2011-07-15

    I am learning json now. $.ajax({ async: true, type: "POST", url: "get.....values.asp", data: "vendorId="+vendor, success: function(json){ alert( "Data retrieved: " + json ); } }); I am using this ajax call to get the data as json and data is coming a

  • Delete JSON object in order to always retrieve its new data in JQuery 2011-12-22

    I used Ajax POST to update a JSON object but when I tried to retrieve the JSON object simultaneously after that, it returned the old data of the JSON object. How do I delete this old object and always retrieve the new one? This how the GET looks like

  • JSON Iteration - My JSON object is being treated as a string literal? 2009-09-28

    This is probably a super easy question but I'm banging my head on it for some reason. Here is the jQuery I have $(function() { $.get(urlGetContainerNumbers, function(data) { console.log(data); for (var idx = 0; idx < data.length; idx++) { var cont

  • binding nested json object value to a form field 2010-05-13

    I am building a dynamic form to edit data in a json object. First, if something like this exists let me know. I would rather not build it but I have searched many times for a tool and have found only tree like structures that require entering quotes.

  • how do I get the form data in a javascript object so I can send it as the data parameter of an $.ajax call 2010-05-18

    How to return json after form.submit()? <form id="NotificationForm" action="<%=Url.Action("Edit",new{Action="Edit"}) %>" method="post" enctype="multipart/form-data" onsubmit='getJsonRequestAfterSubmittingForm(this); return false;'> <%H

  • How to bind functions to the JSON object? 2010-10-14

    function Person(_name, _id, _salary){ this.Name = _name; this.Id = _id; this.Salary = _salary; } Person.prototype.f_IncreaseSalary = function( _percentage ){ this.Salary *= _percentage; } var per = new Person("cem",10,15000); 1) I can access to per.f

  • data transfer using JSON 2011-04-17

    I am trying to get a piece of data from server using JSP technology. I am using JSON object to do so. On client side i am using XMLHttpRequest to get the data. To check whether it works properly, i wrote a piece of code as follow: <head> <sc

  • What annotations and configuration I should make to parse JSON object 2011-06-03

    I have a request(POST or GET), having one variable "data" (coming from Xcode) now data have assigned JSON object data={"method":"Auth","action":"login"} now I have a bean having exactly these two fields(i.e. method,action) now in Spring controller I

  • Converting a django ValuesQuerySet to a json object 2011-07-06

    I'm trying to use the ValuesQuerySet feature in Django to limit the number of fields returned from query to only those I need. I would like to serialize this data set a JSON object However, Django keeps throwing an error. Below I've included my code

  • Difficulty Accessing Values from JSON Object Using PHP- Sunlight Labs congressapi 2011-07-26

    I'm trying to pull values from a JSON object pulled from the Sunlight Labs Congress API using PHP. I'm able to get request response data into a JSON object, but haven't had any success getting specific values out of the object. I can successfully dum

  • Get part of JSON object 2011-08-05

    I'm playing with Google Maps and Geocoding (converting Address to lang/lat coordinates). Everything works fine so far and I'm getting an answer from the google maps server with a file: $address = urlencode( $address ); $url = "

Copyright (C), All Rights Reserved.

processed in 0.119 (s). 11 q(s)