首页 > 解决方案 > yii2 Db column return Incorrect JSON

问题描述

One of my columns in my db( levels table ) has JSON type.

When I write some query like this

   1)  $levels = Levels::find()
              ->select("level_permissions")
              ->column();

   2) $levels = Levels::find()
              ->select("level_permissions")
              ->all();

In second(2) version I will get my json string in " quotes" For example

"{\"name\":\"level_name\",\"active\":\"1\",\"level_administering_level_id\":\"1\"},\"LevelAccessPermission\":{\"31\":\"1\"}"

But in first(1) I have bug it returns

""{\"name\":\"level_name\",\"active\":\"1\",\"level_administering_level_id\":\"1\"},\"LevelAccessPermission\":{\"31\":\"1\"} ""

and when I decode it I get

array(1) { [0]=> string(584) "{"lev_name":"ssssssssss","lev_active":"1","lev_administering_level_id":"1"},"LevelAccessPermission":{"31":"1"}}"

The problem is in quotes. in second version the string is in quotes, but when I use -> column(), I have some "" empty double quotes, then my json, then empty double quotes.

Why in column case ? I get double quotes before and after json. I have it only when I use yii2 -> column().

Any advice... Do you have some bug like this? Any idea?

标签: jsonpostgresqlyii2yii2-model

解决方案


推荐阅读