jQuery访问JSON对象

前端之家收集整理的这篇文章主要介绍了jQuery访问JSON对象前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何使用jQuery访问对象文字中的项目的名称

例如,我将如何阅读“标题”,“链接”,“媒体”等等

{
    "title": "What we do in our free time...","link": "http://www.flickr.com/photos/tnhimmies/4042938515/","media": {"m":"http://farm3.static.flickr.com/2572/4042938515_3a00561320_m.jpg"},"date_taken": "2009-10-24T03:48:10-08:00","description": "<p><a href=\"http://www.flickr.com/people/tnhimmies/\">Darlene,TN Persians (www.tnpurrs.com)<\/a> posted a photo:<\/p> <p><a href=\"http://www.flickr.com/photos/tnhimmies/4042938515/\" title=\"What we do in our free time...\"><img src=\"http://farm3.static.flickr.com/2572/4042938515_3a00561320_m.jpg\" width=\"240\" height=\"230\" alt=\"What we do in our free time...\" /><\/a><\/p> <p>Tennessee Persians<br /> <a href=\"http://www.tnpurrs.com\" rel=\"nofollow\">www.tnpurrs.com<\/a><\/p>","published": "2009-10-25T18:28:36Z","author": "nobody@flickr.com (Darlene,TN Persians (www.tnpurrs.com))","author_id": "66405213@N00","tags": "cat persian tnpurrs"
},

解决方法

您也可以使用 $.each功能
var obj = { one:1,two:2,three:3,four:4,five:5 };

$.each(obj,function(key,value) {
  //..
});

如果您使用for...in语句的方式,我建议您检查该属性是否直接放在被迭代的对象上,因为如果Object.prototype被扩展,则可以使用some issues

for(var key in obj) {
  if (obj.hasOwnProperty(key)){
    // value = obj[key];
  }
}

猜你在找的jQuery相关文章