无法为礼品卡奖品JSON输出设置有效的字符集

时间:2017-03-01 09:30:43

标签: php json content-type

我在使用php输出JSON时出现了一个奇怪的错误:

  

编码无效,期望UTF-8,UTF-16或UTF-32。[代码29,   结构0]

我已尝试将此添加到标题中,如下所示,但到目前为止还没有运气:

header('Content-type: application/json;charset=utf-8');

从此工具返回:https://jsonformatter.curiousconcept.com

JSON Feed位于此处:

https://www.pointsprizes.com/api/mobile/account/prizes/123132

尝试了我能想到的一切,尝试将它设置为16然后32但仍然没有运气。知道问题是什么吗?

1 个答案:

答案 0 :(得分:2)

艾米检查此回复:

{"status":"success","reason":"","device":"","version":"","email":"john.smith@gmail.com","id":"123132","points":"1502","offers":"true","hyprmx":"true","prizes":"true","visit":"true","html":"<!doctype html><html lang='en'><head></head><body><p style='font-weight:900;'>received account_id: 123132</p><p>received device: </p><p>received version: </p></body></html>"}

HTMl也存在于此:

<!doctype html><html lang='en'><head></head><body><p style='font-weight:900;'>received account_id: 123132</p><p>received device: </p><p>received version: </p></body></html>

因为这个html,json_decode()显示:

<br />
<b>Parse error</b>:  syntax error, unexpected 'en' (T_STRING), expecting ',' or ')' in <b>[...][...]</b> on line <b>3</b><br />

当我删除它并json_decode()时,它会给出:

stdClass Object
(
    [status] => success
    [reason] => 
    [device] => 
    [version] => 
    [email] => john.smith@gmail.com
    [id] => 123132
    [points] => 1502
    [offers] => true
    [hyprmx] => true
    [prizes] => true
    [visit] => true
    [html] => 
)