我正试图从我的k2动力Joomla网站上获取JSON。据我所知,我需要将index.php?option=com_k2&id=1&lang=mk&task=category&view=itemlist&format=json
添加到我的URL,然后下载一个joomla.json文件。我现在知道我需要解析这些内容,但我怀疑joomla.json文件中的格式是否正确。
以下是json文件内容的一部分:
{"id":"6","title":"\u0424\u0443\u0441\u0442\u0430\u043d \u041a\u0440\u0438\u0441\u0442\u0438\u043d\u0430","alias":"fustan-kristina","link":"\/katalog\/vencanici\/fustan-kristina.html","catid":"1","introtext":"<ul>\r\n<li>\u041e\u0432\u043e\u0458 \u0444\u0443\u0441\u0442\u0430\u043d \u0435 \u0438\u0437\u0440\u0430\u0431\u043e\u0442\u0435\u043d \u043e\u0434 100% \u0441\u0432\u0438\u043b\u0430.<\/li>\r\n<li>\u041d\u0435\u0436\u0435\u043d \u043c\u0430\u0442\u0435\u0440\u0438\u0458\u0430\u043b<\/li>\r\n<li>\u0414\u043e\u0434\u0430\u0434\u0435\u043d\u0438 \u0446\u0438\u0440\u043a\u043e\u043d\u0438<\/li>\r\n<\/ul>\r\n<p>\u0412\u0438\u0441\u0442\u0438\u043d\u0441\u043a\u0438 \u043d\u0435\u0432\u0435\u0441\u0442\u0438\u043d\u0441\u043a\u0438 \u0444\u0443\u0441\u0442\u0430\u043d<\/p>\r\n<p>\u0411\u0443\u0442\u0438\u043a \u0412\u0438\u043a\u0442\u043e\u0440<\/p>","fulltext":"","extra_fields":[{"id":"1","name":"\u0426\u0435\u043d\u0430","value":"12000 \u0434\u0435\u043d.","type":"textfield","group":"1","published":"1","ordering":"1"},{"id":"6","name":"\u0412\u0435\u0431 \u0421\u0442\u0440\u0430\u043d\u0430","value":"<a href=\"http:\/\/www.domain.mk\" target=\"_blank\">http:\/\/www.domain.mk<\/a>","type":"link","group":"1","published":"1","ordering":"2"}],"created":"2012-07-11 09:42:04","created_by_alias":"","modified":"2012-07-11 11:26:34","featured":"0","image":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_S.jpg","imageWidth":"200","image_caption":"\u0424\u0443\u0441\u0442\u0430\u043d \u041a\u0440\u0438\u0441\u0442\u0438\u043d\u0430","image_credits":"","imageXSmall":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_XS.jpg","imageSmall":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_S.jpg","imageMedium":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_M.jpg","imageLarge":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_L.jpg","imageXLarge":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_XL.jpg","video":null,"video_caption":"","video_credits":"","gallery":null,"hits":"50","category":{"id":"1","name":"\u0412\u0435\u043d\u0447\u0430\u043d\u0438\u0446\u0438","alias":"vencanici","link":"\/katalog\/katalog\/vencanici.html","description":"","image":"","ordering":"1"},"tags":[{"id":"1","name":"kristina","published":"1","link":"\/tag\/kristina.html"},{"id":"2","name":"fustan","published":"1","link":"\/tag\/fustan.html"},{"id":"3","name":"vencanica","published":"1","link":"\/tag\/vencanica.html"}],"attachments":[],"votingPercentage":100,"numOfvotes":"(1 \u0413\u043b\u0430\u0441\u0430\u0458)","author":{"name":"\u0414\u0430\u0440\u043a\u043e \u041f\u0435\u0442\u043a\u043e\u0432\u0441\u043a\u0438","link":"\/blog\/\u0414\u0430\u0440\u043a\u043e-\u041f\u0435\u0442\u043a\u043e\u0432\u0441\u043a\u0438.html","avatar":"http:\/\/www.gravatar.com\/avatar\/bb9f8918a0a63b260d46eb419bf1a894?s=100&default=http%3A%2F%domain.mk%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png","profile":{"gender":null}},"numOfComments":"0","events":{"BeforeDisplay":"","AfterDisplay":"","AfterDisplayTitle":"","BeforeDisplayContent":"","AfterDisplayContent":"","K2BeforeDisplay":"","K2AfterDisplay":"","K2AfterDisplayTitle":"","K2BeforeDisplayContent":"","K2AfterDisplayContent":"","K2CommentsCounter":""}}]}
这个json的格式是否正确,这是我从K2网站获取json内容的方法吗?
答案 0 :(得分:0)
您的JSON字符串末尾有一个额外的] and }
。
删除它们后,你的JSON结果很好而且合法。
{"id":"6","title":"\u0424\u0443\u0441\u0442\u0430\u043d \u041a\u0440\u0438\u0441\u0442\u0438\u043d\u0430","alias":"fustan-kristina","link":"\/katalog\/vencanici\/fustan-kristina.html","catid":"1","introtext":"<ul>\r\n<li>\u041e\u0432\u043e\u0458 \u0444\u0443\u0441\u0442\u0430\u043d \u0435 \u0438\u0437\u0440\u0430\u0431\u043e\u0442\u0435\u043d \u043e\u0434 100% \u0441\u0432\u0438\u043b\u0430.<\/li>\r\n<li>\u041d\u0435\u0436\u0435\u043d \u043c\u0430\u0442\u0435\u0440\u0438\u0458\u0430\u043b<\/li>\r\n<li>\u0414\u043e\u0434\u0430\u0434\u0435\u043d\u0438 \u0446\u0438\u0440\u043a\u043e\u043d\u0438<\/li>\r\n<\/ul>\r\n<p>\u0412\u0438\u0441\u0442\u0438\u043d\u0441\u043a\u0438 \u043d\u0435\u0432\u0435\u0441\u0442\u0438\u043d\u0441\u043a\u0438 \u0444\u0443\u0441\u0442\u0430\u043d<\/p>\r\n<p>\u0411\u0443\u0442\u0438\u043a \u0412\u0438\u043a\u0442\u043e\u0440<\/p>","fulltext":"","extra_fields":[{"id":"1","name":"\u0426\u0435\u043d\u0430","value":"12000 \u0434\u0435\u043d.","type":"textfield","group":"1","published":"1","ordering":"1"},{"id":"6","name":"\u0412\u0435\u0431 \u0421\u0442\u0440\u0430\u043d\u0430","value":"<a href=\"http:\/\/www.domain.mk\" target=\"_blank\">http:\/\/www.domain.mk<\/a>","type":"link","group":"1","published":"1","ordering":"2"}],"created":"2012-07-11 09:42:04","created_by_alias":"","modified":"2012-07-11 11:26:34","featured":"0","image":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_S.jpg","imageWidth":"200","image_caption":"\u0424\u0443\u0441\u0442\u0430\u043d \u041a\u0440\u0438\u0441\u0442\u0438\u043d\u0430","image_credits":"","imageXSmall":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_XS.jpg","imageSmall":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_S.jpg","imageMedium":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_M.jpg","imageLarge":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_L.jpg","imageXLarge":"\/media\/k2\/items\/cache\/ada9a09acea936d776a6f55c82778c43_XL.jpg","video":null,"video_caption":"","video_credits":"","gallery":null,"hits":"50","category":{"id":"1","name":"\u0412\u0435\u043d\u0447\u0430\u043d\u0438\u0446\u0438","alias":"vencanici","link":"\/katalog\/katalog\/vencanici.html","description":"","image":"","ordering":"1"},"tags":[{"id":"1","name":"kristina","published":"1","link":"\/tag\/kristina.html"},{"id":"2","name":"fustan","published":"1","link":"\/tag\/fustan.html"},{"id":"3","name":"vencanica","published":"1","link":"\/tag\/vencanica.html"}],"attachments":[],"votingPercentage":100,"numOfvotes":"(1 \u0413\u043b\u0430\u0441\u0430\u0458)","author":{"name":"\u0414\u0430\u0440\u043a\u043e \u041f\u0435\u0442\u043a\u043e\u0432\u0441\u043a\u0438","link":"\/blog\/\u0414\u0430\u0440\u043a\u043e-\u041f\u0435\u0442\u043a\u043e\u0432\u0441\u043a\u0438.html","avatar":"http:\/\/www.gravatar.com\/avatar\/bb9f8918a0a63b260d46eb419bf1a894?s=100&default=http%3A%2F%domain.mk%2Fcomponents%2Fcom_k2%2Fimages%2Fplaceholder%2Fuser.png","profile":{"gender":null}},"numOfComments":"0","events":{"BeforeDisplay":"","AfterDisplay":"","AfterDisplayTitle":"","BeforeDisplayContent":"","AfterDisplayContent":"","K2BeforeDisplay":"","K2AfterDisplay":"","K2AfterDisplayTitle":"","K2BeforeDisplayContent":"","K2AfterDisplayContent":"","K2CommentsCounter":""}}
使用此站点测试您的JSON字符串。
如果您难以在3D中可视化JSON字符串,请尝试http://jsonviewer.stack.hu/您可以格式化字符串以显示JSON。
答案 1 :(得分:0)
我正在使用&format=json
来建立我的网站。
$.get('//url with format=json',function(d){$('.k2ItemTitle').html(d.item.title)})
我甚至不必使用$ .pareJSON