【问题标题】:PHP SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 6PHP SyntaxError:JSON.parse:第 6 行对象中的属性值之后的预期“,”或“}”
【发布时间】:2017-06-01 10:27:26
【问题描述】:

我是编码初学者,需要您的帮助。 我正在尝试验证 json,但出现此错误:

SyntaxError: JSON.parse: expected ',' or '}' after property value in object at the line 6 column 35

我在我的 php 文件中尝试了这个正则表达式: preg_match_all("/<[\s]*meta[\s]*name='?" . "([^>']*)'?[\s]*" . "content='?([^>']*)'?[\s]*[\/]?[\s]*>/si", $contents, $match);

我的 Json 给了我这个(请参阅附件中的图片以查看“html”中的内容):

`

{ “CMS”:“tumblr”, "title": "Le Blog de Betty - Le Blog de Betty : 博客模式、博客趋势、Betty Autier 的照片模式", “元标签”:{ “视口”:{ "html": "", “内容”:“宽度=设备宽度,最小比例=1,最大比例=1” }, “描述”: { "html": "", "content": "Le Blog de Betty : 博客模式、博客趋势、Betty Autier 的照片模式" }, “发电机”: { "html": "", “内容”:“WPML 版本:3.1.8.3 stt:4,1,2,65;0” }, “OG:语言环境”:{ "html": "", “内容”:“fr_FR” }, “OG:类型”:{ "html": "", “内容”:“网站” }, “OG:标题”:{ "html": "", "content": "Le Blog de Betty - Le Blog de Betty : 博客模式、博客趋势、Betty Autier 的照片模式" }, “OG:描述”:{ "html": "", "content": "Le Blog de Betty : 博客模式、博客趋势、Betty Autier 的照片模式" }, “OG:网址”:{ "html": "", “内容”:“http://leblogdebetty.com/” }, “OG:站点名称”:{ "html": "", “内容”:“贝蒂博客” }, “文章:出版商”:{ "html": "", “内容”:“http://facebook.com/leblogdebetty” } }, “链接”:{ “快捷方式图标”:{ "html": "", “href”:“http://localhost:8888/images/2013/12/favicon.ico” }, “规范”:{ "html": "", “href”:“http://leblogdebetty.com/” }, “下一个”: { "html": "", “href”:“http://leblogdebetty.com/page/2/” }, “出版商”:{ "html": "", "href": "https://plus.google.com/+leblogdebetty" }, “'dns-prefetch'”:{ "html": "", "href": "'//s.w.org' /" }, “样式表”:{ "html": "", “href”:“http://leblogdebetty.com/wp-content/plugins/jetpack/css/jetpack.css?ver=3.4.3” }, “'https://api.w.org/'”:{ "html": "", "href": "'http://leblogdebetty.com/wp-json/' /" } } }

`

Part of Json file

有人可以帮我解决这个问题吗?

【问题讨论】:

  • 你想做什么?从 Json 中获取值?
  • 图片中的json有非转义引号,无效meta\nname="viewport"....
  • @kishor :我正在尝试获取有效的 Json,但我不知道该怎么做。

标签: php json


【解决方案1】:

在适当的字段上使用htmlentities() 函数将引号转换为它们的" 表示形式。

您也可以尝试从" 转义到\"addslashes()

【讨论】:

  • 应该被接受的答案。您可能需要迭代您的结果集,在每个字段上调用它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-10
  • 2021-09-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多