PHP json_decode()返回null

时间:2019-03-18 11:11:37

标签: php json

我正在使用cloudinary上传图像。我正在尝试解码图像上传插件生成的json字符串,但它返回null。我是json plese帮助的新手

这是json字符串

[{"public_id":"pdf/Eagle_s_Crest_s1khaa","version":1552905253,"signature":"976a2475ba858beeb33d533b4bdd897c7730574c","width":3543,"height":5315,"format":"png","resource_type":"image","created_at":"2019-03-18T10:34:13Z","tags":[],"bytes":579592,"type":"upload","etag":"9c1ce7ee6f0d1a7ff540d9e06cfbc2bf","placeholder":false,"url":"http://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","secure_url":"https://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","access_mode":"public","existing":false,"original_filename":"Eagle ◀"

2 个答案:

答案 0 :(得分:1)

它返回null,因为它不是有效的JSON。末尾缺少}]

在这里比较:

<?php

var_dump(json_decode('[{"public_id":"pdf/Eagle_s_Crest_s1khaa","version":1552905253,"signature":"976a2475ba858beeb33d533b4bdd897c7730574c","width":3543,"height":5315,"format":"png","resource_type":"image","created_at":"2019-03-18T10:34:13Z","tags":[],"bytes":579592,"type":"upload","etag":"9c1ce7ee6f0d1a7ff540d9e06cfbc2bf","placeholder":false,"url":"http://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","secure_url":"https://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","access_mode":"public","existing":false,"original_filename":"Eagle ◀"'));

var_dump(json_decode('[{"public_id":"pdf/Eagle_s_Crest_s1khaa","version":1552905253,"signature":"976a2475ba858beeb33d533b4bdd897c7730574c","width":3543,"height":5315,"format":"png","resource_type":"image","created_at":"2019-03-18T10:34:13Z","tags":[],"bytes":579592,"type":"upload","etag":"9c1ce7ee6f0d1a7ff540d9e06cfbc2bf","placeholder":false,"url":"http://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","secure_url":"https://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","access_mode":"public","existing":false,"original_filename":"Eagle ◀"}]'));

您在此处粘贴了错误的JSON,或者上传插件返回了无效的JSON。

答案 1 :(得分:-1)

如果您使用json_decode,建议您查看文档:{​​{3}} 由于我们这里没有您的PHP代码,我想您的代码中不包含第二个参数“ assoc”,这可能是您遇到麻烦的原因