php - 无法在php中进行json解码
问题描述
我有像下面这样的字符串我正在尝试对其进行 json_decode() 但它给了我空值
{
"products": [{
"product_id": 6,
"product_name": "Reusable Baby Cloth Diaper with 5 Layered Baby Insert Pads (Pack of 2), id:(6)",
"quantity": Reusable Baby Cloth Diaper with 5 Layered Baby Insert Pads (Pack of 2), id:(6),
"strikeprice": ,"cart_total": 120,"delivery_charge": 10,"delivery_discount": ,"discount": 20,"gullack_discount": 10,"gullack_points_used": 20,"max_points_usable_original": ,"final_price": 200,"gullack_point_win": 200,"product_image": "","referrer": null,"share_points_given": 0,"order_status": 1"max_points_usable":0}],"orderDetails": {"address_id": 406,"phone": "9284759237","payment_mode": ,"successCallbackUrl": "http://localhost:4200/ordersuccess/{orderId}","failedCallbackUrl": "http://localhost:4200/placeorder#paymentFailed","campaign_id": "NA","query": "","offer_id": null,"query_string": ""}
}
提前致谢
解决方案
这部分 JSON 无效:
"quantity": Reusable Baby Cloth Diaper with 5 Layered Baby Insert Pads (Pack of 2), id:(6),
我不确定为什么数量是字符串而不是数字。但既然是这样,它就需要引号:
"quantity": "Reusable Baby Cloth Diaper with 5 Layered Baby Insert Pads (Pack of 2), id:(6)",
您应该修复创建 JSON 的代码。如果它使用 JSON 库,这种类型的错误将是不可能的,因此它必须以一种特别的方式构造 JSON,并且做错了。
推荐阅读
- python - 在 Python 中创建随机字符串
- assembly - Proteus 8 - 破模拟
- java - 更新到 64 位版本 google play
- c# - 如何修复此 for 循环以比较两个 char 数组?
- python - 在 Windows 上升级 Python 3.7 的 pip 但遇到权限错误
- windows - 如何从 Windows 中的文件夹中提取特定的文件列表?
- rest - 唯一资源的 REST 资源命名
- http - URL 缓存和多租户
- c# - 无法加载文件或程序集“Newtonsoft.Json,版本=10.0.0.0,文化=中性,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一
- buildbot - 如何将文件附加到 buildbot mailnotifier