JSON 解码 Perl - 格式错误的 JSON 字符串



当我尝试解码它时,我正在从以 JSON 格式存储的 MYSQL 数据库中获取数据,我收到错误 格式错误的 JSON 有什么想法吗? $VAR 1 是\I 从数据库中获取的变量

使用JSON; 使用数据::D umper; $VAR 1 = [ '{"description":["],"last_modified_date_min":["]}' ]; $DecodeS = decode_json($VAR 1(; 打印自卸车$DecodeS;

格式错误的 JSON 字符串,既不是数组、对象、数字、字符串或原子,字符偏移量为 0(在"ARRAY(0x7f8674002ee8..."之前(

[ ... ]创建一个数组并返回对该数组的引用,因此$VAR1包含一个引用。您正在将此引用(恰好字符串化为ARRAY(0x7f8674002ee8)(传递给decode_json而不是 JSON 字符串。

你想要

$VAR1 = [ '{"description":[""],"last_modified_date_min":[""]}' ];
decode_json($VAR1->[0])

$VAR1 = '{"description":[""],"last_modified_date_min":[""]}';
decode_json($VAR1)

最新更新