English 中文(简体)
与json阵列的侵扰
原标题:Struggling with json array

Ive改变了一只 j子的 object子,将其改成一个阵列,使用makeArray美元,现在正在努力从这个阵列获得价值。 想在气候条件下发挥节奏和价值。 阵列的打印如下。

[
Object
data: Object
current_condition: Array[1]
0: Object
cloudcover: "50"
humidity: "72"
observation_time: "10:25 AM"
precipMM: "0.1"
pressure: "1005"
temp_C: "13"
temp_F: "55"
visibility: "10"
weatherCode: "122"
 weatherDesc: Array[1]
 0: Object
  value: "Overcast"
__proto__: Object
length: 1
__proto__: Array[0]
weatherIconUrl: Array[1]
winddir16Point: "SSW"
winddirDegree: "210"
windspeedKmph: "19"
windspeedMiles: "12"
__proto__: Object
length: 1
__proto__: Array[0]
request: Array[1]
__proto__: Object
__proto__: Object
问题回答

你可以尝试:

alert(yourObject.temp_C>;

并且

alert(yourObject.weatherDesc. Value);

您没有必要将其转换成一个阵列:

你们不需要把目标变成一个阵列,而只能获得你们所需要的财产:

var o = object_retrieved_from_api;
o.temp_c;
o.weatherDesc[0].value;

如果你将其转换成一个阵列,那么仅仅必须把第一物体的阵列索引:

var a = $.makeArray(object_retrieved_from_api);
a[0].temp_c;
a[0].weatherDesc[0].value;

The whole point of JSON is that it is already a Javascript object, so you don t need any complex parsing logic in order to get the data out. Try out the following code and you ll see how easy it is to get data from a JSON web service.

$.getJSON( your JSON URL here , function(data) {

  $.each(data.current_condition, function() {
    alert(this.temp_C + "C " + this.weatherDesc[0].value);
  });

});




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签