JSON_EXTRACT不适用于嵌套的json数据

时间:2021-08-18 15:54:42

I want to select the data from my table which is json data so to show my table data is like this :

我想从我的表中选择json数据中的数据,以便显示我的表数据是这样的:

user_id:    1

metaname:  mymetaname

meta_value:    a:1:{i:0;a:10:{s:7:"street1";s:36:"shiv plaza";s:4:"city";s:5:"surat";s:5:"state";s:7:"gujarat";s:7:"zipcode";s:6:"395010";s:14:"dollet_country";s:2:"IN";s:10:"tostreet1l";s:5:"surat";s:7:"tocityl";s:5:"surat";s:8:"tostatel";s:5:"surat";s:10:"tozipcodel";s:6:"395000";s:17:"todollet_countryl";s:2:"IN";}}

And i am trying to run this query :

我正在尝试运行此查询:

SELECT user_id,JSON_EXTRACT(meta_value, '$."city"') FROM  `usermetatable`

But it's showing error :

但它显示错误:

[Invalid JSON text in argument 1 to function json_extract: "Invalid value." at position 0.]

[参数1中的无效JSON文本用于函数json_extract:“无效值。”在位置0]

My json data in table can not be changed to other and it's correct JSON for sure, Could anyone correct above query ?

我的表中的json数据无法更改为其他数据并且肯定是正确的JSON,任何人都可以更正上述查询吗?

1 个解决方案

#1


3  

That's not JSON data. It looks like a serialized PHP object. See http://php.net/serialize

那不是JSON数据。它看起来像一个序列化的PHP对象。见http://php.net/serialize

There's no MySQL function for extracting a field from that serialized object. You should fetch the whole object into a PHP app, and call unserialize() on it, then access the object members.

没有用于从该序列化对象中提取字段的MySQL函数。您应该将整个对象提取到PHP应用程序中,并在其上调用unserialize(),然后访问对象成员。

#1


3  

That's not JSON data. It looks like a serialized PHP object. See http://php.net/serialize

那不是JSON数据。它看起来像一个序列化的PHP对象。见http://php.net/serialize

There's no MySQL function for extracting a field from that serialized object. You should fetch the whole object into a PHP app, and call unserialize() on it, then access the object members.

没有用于从该序列化对象中提取字段的MySQL函数。您应该将整个对象提取到PHP应用程序中,并在其上调用unserialize(),然后访问对象成员。