json_array:创建Json数组
- ["a", "b", "v"]
insert into order_remarks(remarks) values(json_array("a","b","v"));
普通的json数组。
- ["a", "b", "{\"c\":\"d\",\"e\":\"f\"}"]
由于json中的所有引号必须使用双引号,但又不能双引号里包含双引号,所以上面的第一个例子都必须使用\转义。第三个元素是一个字符串,需要对原数组json_decode之后在对第三个元素json_decode。
insert into order_remarks(remarks) values(json_array("a","b",'{"c":"d","e":"f"}'));
- ["a", "b", {"c":"d","e":"f"}]
json数组里嵌入json对象
insert into order_remarks(remarks) values(json_array("a","b",json_object("c","d","e","f")));
json_object: 创建Json对象
- {"name":"xiaoyu","old":12,"height":"165.1"}
普通的json对象
insert into order_remarks(remarks) values(json_object("name","xiaoyu","old",12,"height","165.1"));
- {"name":"xioayu","old":12,"family":"[\"dad\",\"mom\"]"}
乍一看像是Json对象里包了一个json数组,仔细看其实第三个元素是一个字符串,这个整体还是一个json对象。
insert into order_remarks(remarks) values(json_object("name","xiaoyu","old",12,"family",'["dad","mom"]'));
- {"name":"xioayu","old":12,"family":["dad","mom"]}
json对象套json数组
insert into order_remarks(remarks) values(json_object("name","xiaoyu","old",12,"family",json_array("dad","mom")));
网友评论