奇妙的JSON

摘要:今天发现一个申请的json解析情况,记录一下

先查看下面两个json字符串

$str1 = '[
{
    "englishname":"William Chen",
    "class":"01.70.04."
},
{
    "englishname":"Zoe Bai",
    "class":"01.50.08.04."
},
{
    "englishname":"Zoe Zhu",
    "class":"01.07.06."
}
]';

$str = "[
{
    'text1':'Parent 2',
    'text2':'#parent2'
},
{
    'text1':'Parent 3',
    'text2':'#parent3'
},
{
    'text1':'Parent 4',
    'text2':'#parent4'
},
{
    'text1':'Parent 5',
    'text2':'#parent5'
}
]";

执行结果

  • str1可以正常访问
  • str在使用json_deocde的时候显示为null

分析

json数据需要使用双引号包裹,单引号会发生这个问题。
评论
  • 2019-04-17 17:40:10 by Eric Guo
    之前在json.cn上测试,发现只会说错误,并不能提示错误类型,https://www.sojson.com/simple_json.html 这个地址可以,用起来不错