Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从JSON对象中获取数据?_Javascript_Json_Vbscript_Arcgis Server - Fatal编程技术网

Javascript 如何从JSON对象中获取数据?

Javascript 如何从JSON对象中获取数据?,javascript,json,vbscript,arcgis-server,Javascript,Json,Vbscript,Arcgis Server,我正在使用JSON.org中提供的JSON.js <% JSONReturn = GetDistance(Sample) // return a string in JSON format (Arcgis server Solve route function) JSONObject = JSON.parse(JSONReturn,"Total_Length") %> }试试这个 <%@ Language=VBScript %> <script language

我正在使用JSON.org中提供的JSON.js

<%
JSONReturn = GetDistance(Sample) // return a string in JSON format (Arcgis server Solve route function)

JSONObject = JSON.parse(JSONReturn,"Total_Length")
%>
}试试这个

<%@ Language=VBScript %>
<script language="JavaScript" runat="server">
/**************
Original file located at : https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js
***************/
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(Object.hasOwnProperty.call(object,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(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}return reviver.call(holder,key,value);}({'':result},'')):result;};}());
</script>
<%
'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
%>

/**************
原始文件位于:https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js
***************/

var json\u 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(“预期的是“+c+”””,而不是“,”=ch:+=ch;}返回函数;text+=1;}{var number,string='';if(ch=='-'){string='-';next('-');}而(ch>='0'&&ch='0'&&ch='0'&&ch您可以通过点分隔JSON对象的属性来访问它们。就像任何其他对象一样

在您的例子中,
JSONObject.routes.features[0].attributes.Total_Length


功能[0]
表示数组的第一个元素,但您可能必须在其上循环。

您的问题与经典asp无关,因此我已从标题和标记中删除了对它的提及。请随意将它们添加到您不同意的后面。我正在用经典asp编写它。它怎么可能不相关?因为您要问的问题是JSON和javascripte、 经典ASP是如何发挥作用的?@seesee ASP是一个web平台,在这里完全不相关。相关的是语言。您的代码可能是VBScript或JScript。phihag更有意义。是的,它应该是VBScript:P
<%@ Language=VBScript %>
<script language="JavaScript" runat="server">
/**************
Original file located at : https://github.com/douglascrockford/JSON-js/blob/master/json_parse.js
***************/
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(Object.hasOwnProperty.call(object,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(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}return reviver.call(holder,key,value);}({'':result},'')):result;};}());
</script>
<%
'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
%>