1

我正在尝试从我的 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&amp;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 内容的正确方法吗?

4

2 回答 2

0

] and }您在 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&amp;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 字符串。

http://jsonlint.com/

如果您在 3D 中可视化 JSON 字符串时遇到困难,请尝试http://jsonviewer.stack.hu/您可以格式化字符串以可视化 JSON。

于 2012-07-19T06:45:25.433 回答
0

&format=json也用它来构建我的网站。

$.get('//url with format=json',function(d){$('.k2ItemTitle').html(d.item.title)})

我什至不必使用 $.pareJSON

于 2015-08-17T14:43:49.407 回答