Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在postgres列中存储json值_Json_Postgresql - Fatal编程技术网

如何在postgres列中存储json值

如何在postgres列中存储json值,json,postgresql,Json,Postgresql,我有一个有两列的表,一列应该存储int,另一列应该存储json 这里是我要存储在表中的数据 id,polygon 1,"{""type"": ""Feature"", ""properties"": { ""stroke"": ""#555555"", ""stroke-width"": 2, ""stroke-opacity"": 1, ""fill"": ""#00aa22"", ""fill-opaci

我有一个有两列的表,一列应该存储int,另一列应该存储json

这里是我要存储在表中的数据

id,polygon
1,"{""type"": ""Feature"",
    ""properties"": {
        ""stroke"": ""#555555"",
        ""stroke-width"": 2,
        ""stroke-opacity"": 1,
        ""fill"": ""#00aa22"",
        ""fill-opacity"": 0.5
    },
    ""geometry"": {
        ""type"": ""Polygon"",
        ""coordinates"": [
            [
                [-76.97021484375,
                    40.17887331434696
                ],
                [-74.02587890625,
                    39.842286020743394
                ],
                [-73.4326171875,
                    41.713930073371294
                ],
                [-76.79443359375,
                    41.94314874732696
                ],
                [-76.97021484375,
                    40.17887331434696
                ]
            ]
        ]
    }
}"
我厌倦了在postgres中存储以下内容:

insert into gjl_polygon values(1,'"{""type"": 
""Feature"",""properties"": {""stroke"": ""#555555"",""stroke- 
width"": 2,""stroke-opacity"": 1,""fill"": ""#00aa22"",""fill- 
opacity"": 0.5},""geometry"": {""type"": 
""Polygon"",""coordinates"": 
[[[-76.97021484375,40.17887331434696],[-74.02587890625, 
39.842286020743394 ],[-73.4326171875, 41.713930073371294], 
[-76.79443359375,41.94314874732696], 
[-76.97021484375,40.17887331434696]]]}}"');
我犯了以下错误

Expecting ':' delimiter: line 1 column 4 (char 3)

代码的问题是使用了两次双引号。尝试按如下方式编辑:

{
    "type": "Feature",
    "properties": {
        "stroke": "#555555",
        "stroke-width": 2,
        "stroke-opacity": 1,
        "fill": "#00aa22",
        "fill-opacity": 0.5
    },
    "geometry": {
        "type": "Polygon",
        "coordinates": [
            [
                [-76.97021484375,
                    40.17887331434696
                ],
                [-74.02587890625,
                    39.842286020743394
                ],
                [-73.4326171875,
                    41.713930073371294
                ],
                [-76.79443359375,
                    41.94314874732696
                ],
                [-76.97021484375,
                    40.17887331434696
                ]
            ]
        ]
    }
}

上面的JSON是一个有效的JSON字符串,它应该按预期工作。

看起来您有一个字符串包装在字符串
'“{”type”“:“Feature”“…”
中,这可能更像
'{”type:“Feature”,…
而没有额外的双引号
尝试删除额外的双引号会导致以下错误,应为“:”分隔符:第1行第4列(字符3)嗯,这和您最初提到的EDI是同一个错误,即您正在执行的实际查询?在不应该有新行的地方包括新行?您是否删除了字符串开头和结尾的双引号(这些不是双引号)