Json对象解析错误 [英] Json Object parse error

查看:316
本文介绍了Json对象解析错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将数据存储在我的cassandra数据库中作为字符串,我想检索字符串并将其转换为json。我得到一个例外



发生类型为Newtonsoft.Json.JsonReaderException的未处理异常



数据存储有问题?或我正在做其他事情吗?



我的查询是:

  INSERT INTO table2(key1,col1)values('5',{'url':'{hello:
{hi:{hey:1,time: 5}},
{reg:{hey:1,time:1 }}},
task:1,retry:00,
max:5,call:140


在我的数据库中,当我点击地图< text,text>列,它存储为:

{\hello\:\r\\\

{\subscription_atrisk\:{\hey \ :\1 \,\time\:\100 \}},
{\reg\:{\hey \ \1 \,\time\:\2000\}},
\task\:\0 \,\retry \:\300 \,\max \:\5 \,\call\:\14400\}



在我的c#代码中,我尝试

  string s ={\hello\:\r\\\
{\subscription_atrisk\:{\hey \:\1 \ \\time\:\100\}},{\reg\:{\hey \:\1 \,\time\ :\2000\}},\task\:\0 \,\retry\:\300\,\max \ :\5\,\call\:\14400\;
Jobject json = Jobject.Parse(s); // Get a Error here。

任何人都可以点亮这个吗?

解决方案

看起来您缺少一个关闭}
尝试:

  string s ={\hello\:{\subscription_atrisk\:{\hey \:\1 \,\time\:\100\}},\missing_key\:{\reg\:{\hey \:\ 1\,\time\:\2000 \}},\task\:\0 \,\retry\:\\ 300\,\max\:\5\,\call\:\14400\}; 


I am storing data in my cassandra database as string and i want to retrieve the string and convert it into json. i get an exception saying

An unhandled exception of type 'Newtonsoft.Json.JsonReaderException' happened

is there something wrong with the data stored ? or i am doing some other thing wrong ?

My query is :

INSERT INTO table2(key1,col1) values ('5',{'url':'{"hello":
    {"hi":{"hey":"1","time":"5"}},
    {"reg":{"hey":"1","time":"1"}},
    {"install":{"hey":"0"}}},
    "task":"1","retry":"00",
    "max":"5","call":"140"'});


In my db when i click the map<text,text> column, it gets stored as : 

 {\"hello\":\r\n    
    {\"subscription_atrisk\":{\"hey\":\"1\",\"time\":\"100\"}},
    {\"reg\":{\"hey\":\"1\",\"time\":\"2000\"}},
\"task\":\"0\",\"retry\":\"300\",\"max\":\"5\",\"call\":\"14400\"}

in my c# code, i try

string s = "{\"hello\":\r\n    {\"subscription_atrisk\":{\"hey\":\"1\",\"time\":\"100\"}},{\"reg\":{\"hey\":\"1\",\"time\":\"2000\"}},\"task\":\"0\",\"retry\":\"300\",\"max\":\"5\",\"call\":\"14400\"";
Jobject json = Jobject.Parse(s); //Get an Error here.

Could anyone please throw some light on this ?

解决方案

Looks like you're missing a closing } Try:

string s = "{\"hello\": {\"subscription_atrisk\":{\"hey\":\"1\",\"time\":\"100\"}}, \"missing_key\": {\"reg\":{\"hey\":\"1\",\"time\":\"2000\"}},\"task\":\"0\",\"retry\":\"300\",\"max\":\"5\",\"call\":\"14400\"}";

这篇关于Json对象解析错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆