【问题标题】:Parse JSON with special characters into Array in PHP在 PHP 中将带有特殊字符的 JSON 解析为数组
【发布时间】:2018-04-29 19:24:49
【问题描述】:
{
    "api_response": "{\"LeadRefNumber\":\"23223222433534543554\",\"ApplicationNumber\":\"2323343434234234\",\"StatusCode\":\"3456\",\"ProcessingStatus\":\"111\",\"CreditLimit\":\"5454554\",\"Messages\":{\"Message\":\"test.\"}}"
}

注意:以上是 json 编码的,但即使使用 json_decode() 解码 json,也无法将其作为数组访问。

【问题讨论】:

  • 请您edit 提供您运行的代码示例、预期输出和实际输出。 “特殊字符”是什么意思?
  • 这是一个对象的 JSON 表示;其属性 api_reponse 的值是另一个 JSON。您也必须 decode it 才能使用它。

标签: php json parsing toarray


【解决方案1】:
$creditLimit = {"api_response":"{\"LeadRefNumber\":\"3434343345435453\",\"ApplicationNumber\":\"5345345345345534\",\"StatusCode\":\"13420\",\"ProcessingStatus\":\"145\",\"CreditLimit\":\"4500000\",\"Messages\":{\"Message\":\"Test\"}}"};

$arrCreditLimit = json_decode($creditLimit['api_response'], true);

print_r("CreditLimit".$arrCreditLimit['CreditLimit']);

输出:

信用额度:4500000

通过上述方法找到了解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-07
    • 2011-08-21
    • 1970-01-01
    • 2016-06-09
    • 2018-04-09
    • 2023-04-03
    • 1970-01-01
    相关资源
    最近更新 更多