0

我有以下 JSON

{
  "eventSummaryList": [
    {
      "customer": "189256",
      "data": "{\"cliente\":\"189256\",\"data_posicao\":\"1491426372\",\"gps_valido\":\"1\",\"horimetro\":\"120561\",\"ibuttonHex\":\"0\",\"ibuttonPart1\":\"0\",\"ibuttonPart2\":\"0\",\"id_evento\":\"null\",\"id_motorista\":\"0\",\"ignicao\":\"1\",\"latitude\":\"-2222222\",\"longitude\":\"-2222222\",\"odometro\":\"253692\",\"pos_memoria\":\"0\",\"veiculo\":\"44444\",\"velocidade\":\"50\"}",
      "identifierEventRule": "77404",
      "identifierRule": "6",
      "identifierSummary": "28901976",
      "rule": "velocidade_maior_que",
      "status": 1,
      "vehicle": "44444"
    }
  ],
  "header": {
    "mensagem": {
      "estilo": "SUCCESS",
      "mensagem": "Successfully executed service",
      "plataforma": "EVENT_POINT",
      "status": "SUCESSO"
    }
  }
}

而且我需要提取包含另一个json的“数据”中的值“velocidade”。

我正在使用以下语法,但它返回 null。

select  cast((value::json ->'data')::json->> 'velocidade' AS   int)    AS velocidade, 
4

1 回答 1

1

尝试:

SELECT ((value::json #>> '{eventSummaryList,0,data}')::json ->> 'velocidade')::int

#>>or->>运算符是关键。如果你使用#>or ->,你最终会得到一个 json 编码的 json 字符串。顺便说一句,这真的是一个混乱的模型,我会考虑首先/而不是修复它的输入。)

http://rextester.com/THVYFK9026

于 2017-04-11T11:16:49.830 回答