如何用JS纠正解析json

时间:2015-04-25 12:30:05

标签: javascript html json parsing

我写web应用程序生成json

    [  
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":2,
      "time":"19 Apr. 2015",
      "viewed":"4"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/xaYMRUN2bBkNt.gif",
      "title":"No title :-(",
      "color":3,
      "time":"19 Apr. 2015",
      "viewed":"1"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/ULzouOE48lyVL.gif",
      "title":"gff",
      "color":4,
      "time":"19 Apr. 2015",
      "viewed":"335"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/4uIAIQQHPn14K.gif",
      "title":"No title :-(",
      "color":5,
      "time":"19 Apr. 2015",
      "viewed":"2"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":1,
      "time":"19 Apr. 2015",
      "viewed":"1"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":2,
      "time":"18 Apr. 2015",
      "viewed":"1"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/t7K2bTku553Zr.gif",
      "title":"ggdd",
      "color":3,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":4,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/hv0Wxd2TcakCU.gif",
      "title":"test",
      "color":5,
      "time":"16 Apr. 2015",
      "viewed":"8"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/Vgp7XhIMqAYYL.gif",
      "title":"ggc",
      "color":1,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":2,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/qqPxYFV5wp5c1.gif",
      "title":"",
      "color":3,
      "time":"16 Apr. 2015",
      "viewed":"8"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"edfft",
      "color":4,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":5,
      "time":"16 Apr. 2015",
      "viewed":"25"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":1,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":2,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":3,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"gfxdrf",
      "color":4,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":5,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/pUnRwiaKCfmG4.gif",
      "title":"\u043f\u0430",
      "color":1,
      "time":"16 Apr. 2015",
      "viewed":"11"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":2,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/d3RuSY5doO8b3.gif",
      "title":"hgdd",
      "color":3,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"img\/video_default.gif",
      "title":"No title :-(",
      "color":4,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/bGLqjgUUaimuP.gif",
      "title":"gdd",
      "color":5,
      "time":"16 Apr. 2015",
      "viewed":"7"
   },
   "rows",
   {  
      "url":"android\/uploads_i\/udkwCVrJeYMb6.gif",
      "title":"title",
      "color":1,
      "time":"16 Apr. 2015",
      "viewed":"7"
   }
]

请帮助我,我如何用Javascript解析它以访问所有对象项,谢谢

1 个答案:

答案 0 :(得分:0)

使用JSON.parse

var result = JSON.parse(data);

要获得标题,您可以使用

var title = result[1]['title'];