小编Ema*_*emi的帖子

无法在 PHP 中解码 JSON 值

我没有找到解决方案。

\n\n

我有一个 API 女巫给我 JSON 响应,

\n\n

http://api.vajehyab.com/v2/public/?q=%D8%B3%D9%84%D8%A7%D9%85&developer=stackoverflow

\n\n

是这样的,

\n\n
\n

{“搜索”:{“q”:“\\ u0633 \\ u0644 \\ u0627 \\ u0645”,“代码”:200},“数据”:{“标题”:“\\ u0633 \\ u0644 \\ u0627\\u0645","发音":"","文字":"(\\u0633\\u064e) [ \\u0639 . ] (\\u0645\\u0635 \\u0644 .) 1 - \\u062f\ \u0631\u0648\u062f \u06af\u0641\u062a\u0646 .2 - \u0628\u06cc \u06af\u0632\u0646\u062f \u0634\u062f\u0646 . 3 - \\u06af\\u0631\\u062f\\u0646 \\u0646\\u0647\\u0627\\u062f\\u0646 . \\u061b ~ \\u0639\\u0644\\u06cc\\u06a9 \\u062f \\u0631\\u0648\\u062f \\u0628\\u0631 \\u062a\\u0648 \\u0628\\u0627\\u062f.\\u061b ~ \\u0639\\u0644\\u06cc\\u06a9\\u0645 \\u062f\\u0631\\u0648\\u062f \\u0628\\u0631 \\u0634\\u0645\\u0627。”,“来源”:“\\u0641\\u0631\\u0647\\u0646\\u06af \\u0641\\u0627\\u0631\\u0633\\u06cc \\u0645\\u0639\\u06cc\\u0646 | \\u0648\\u0627\\u0698\\u0647 \\u06cc\\u0627\\u0628" ,"永久链接":"?q=%D8%B3%D9%84%D8%A7%D9%85"},"错误":{"消息":"","原因":""},"广告":{"text":"","url":""}}

\n
\n\n

它似乎没有问题,我可以在其他工具中解码它,但 PHP,我不能在 PHP 中解码它

\n\n
$json = file_get_contents(\'http://api.vajehyab.com/v2/public/?q=\'.urlencode(\'\xd8\xb3\xd9\x84\xd8\xa7\xd9\x85\').\'&developer=stackoverflow\');\nvar_dump(json_decode($json)); // null\n …
Run Code Online (Sandbox Code Playgroud)

php json decode decoding

5
推荐指数
1
解决办法
1498
查看次数

MarshalJSON错误,顶级后无效字符"g"

我为我的ID制作了一个自定义类型:

type ID uint

func (id ID) MarshalJSON() ([]byte, error) {
    e, _ := HashIDs.Encode([]int{int(id)})
    fmt.Println(e) /// 34gj
    return []byte(e), nil
}

func (id *ID) Scan(value interface{}) error {
    *id = ID(value.(int64))
    return nil
}
Run Code Online (Sandbox Code Playgroud)

我使用HashIDs包对我的id进行编码,以便用户无法在客户端读取它们.但是我收到了这个错误:

json:为类型types.ID调用MarshalJSON时出错:顶级值后无效字符'g'

json marshalling go hashids

1
推荐指数
1
解决办法
6037
查看次数

标签 统计

json ×2

decode ×1

decoding ×1

go ×1

hashids ×1

marshalling ×1

php ×1