sql中json解析
你好!
with t as (select 'a:[{f:,h:,checindate:''month1:,year: ,day: '',checkoutdate:''month:,year: ,day: '',},
{checindate:''month2:,year: ,day: ,'',checkoutdate:''month:,year: ,day},
{checindate:''month3:,year: ,day: ,'',checkoutdate:''month:,year: ,day}]' str from dual)
,t1 as (SELECT substr(str,instr(str,'[')+1,instr(str,']')-instr(str,'[')-1) str FROM T)
,t2 as (select substr(str,instr(str,'{')+1,instr(str,'}')-instr(str,'{')-1) str from t1)
select str,substr(str,instr(str,'checindate')+12, instr(str,'checkoutdate')-instr(str,'checindate')-12) from t2;
得到第一个checindate,直接截取字符串就可以了
别搞得那么复杂了
C++json解析
代码示例:
#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
using namespace std;
int main()
{
string strJsonContent = "{\"role_id\": 1,\"occupation\": \"paladin\",\"camp\": \"alliance\"}";
int nRoleDd = 0;
string strOccupation = "";
string strCamp = "";
Json::Reader reader;
Json::Value root;
if (reader.parse(strJsonContent, root))
{
nRoleDd = root["role_id"].asInt();
strOccupation = root["occupation"].asString();
strCamp = root["camp"].asString();
}
cout << "role_id is: " << nRoleDd << endl;
cout << "occupation is: " << strOccupation << endl;
cout << "camp is: " << strCamp << endl;
return 0;
}
还没有评论,来说两句吧...