Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.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对象中的特定atribute对_Javascript_Php_Jquery_Json_Object - Fatal编程技术网

Javascript 访问json对象中的特定atribute对

Javascript 访问json对象中的特定atribute对,javascript,php,jquery,json,object,Javascript,Php,Jquery,Json,Object,我需要访问温度并将其附加到我的页面中,如果这些都是对象,那么我想我不能使用索引,因为顺序无关紧要,这让我很反感 { "response": { "version": "0.1", "termsofService": "http://www.wunderground.com/weather/api/d/terms.html", "features": { "conditions": 1 } }, "current_observation": { "image": { "url": "ht

我需要访问温度并将其附加到我的页面中,如果这些都是对象,那么我想我不能使用索引,因为顺序无关紧要,这让我很反感

{
"response": {
"version": "0.1",
"termsofService": "http://www.wunderground.com/weather/api/d/terms.html",
"features": {
  "conditions": 1
 }
},
"current_observation": {
"image": {
  "url": "http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png",
  "title": "Weather Underground",
  "link": "http://www.wunderground.com"
},
"display_location": {
  "full": "Toms River, NJ",
  "city": "Toms River"

},
"observation_location": {
  "full": "Stonehedge, Toms River, New Jersey",
  "city": "Stonehedge, Toms River",
  "state": "New Jersey",
  "country": "US"

},
"estimated": {},
"station_id": "KNJTOMSR5",
"observation_time": "Last Updated on April 11, 10:56 PM EDT",
"observation_time_rfc822": "Fri, 11 Apr 2014 22:56:39 -0400",
"observation_epoch": "1397271399",
"local_time_rfc822": "Fri, 11 Apr 2014 22:56:40 -0400",
"local_epoch": "1397271400",
"local_tz_short": "EDT",
"local_tz_long": "America/New_York",
"local_tz_offset": "-0400",
"weather": "Clear",
**"temperature_string": "59.6 F (15.3 C)"**

 }
}
我现在的javascript就是这样,因为我还没有弄清楚如何访问这个项目

$(function() {
$("#getzip").submit(function() {
var zip_data =$(this).serialize();
    $.getJSON("get_weather.php",null, function(data); {
我需要将它附加到我页面的dom中,我想它应该是这样的

   (#output).append(data.temperature_string);

log(data[“temperature\u string”])应该访问该数据。

将json对象转换为javascript

像这样使用

Php中的

 $json ='{"temperature":"36 c"}';
Javascript中的

$.post("get_weather.php",null, function(data){
 var temperature = data.temperature; // here you'll get temperature from json into variable
 console.log(temperature);
           },"json");

仅此而已

您的JSON看起来不完整,但请尝试
zip\u data.temperature\u string
。如果它是一个数组,则使用
zip\u数据[i]在数组中循环。温度字符串
我只参与了json的一部分,因为它是一个巨大的文件,我只需要访问这个临时实例,如果它有帮助的话,请参阅如果这个小提琴有帮助的话,它看起来像是你想要的
。当前的观察。温度字符串
这个数据中没有数组,只是一个相互嵌套的对象列表,我从顶部开始,只粘贴到我需要的值@Chase,我会检查出来。实际上,链接是dead@CoreyBuchillon-它试图包含连字符:try jsfiddle.net/mwr58/1/I应该更清楚,我需要访问它并将其附加到我页面的DOM中,以便我可以执行类似(#output.append)的操作(data[“temperature_string]”);那会解决我的问题