伪代码
string json="{
"data": {
"name": "test",
"sex": 1
";}
}"
JObject obj = JObject.Parse(json);
string name= (string)obj["data"]["name"]; //正常
string sex= (string)obj["data"]["sex"]; //sex的值为数字,且没有带双引号,错误现在就是不能取不带双引号,值为阿拉伯数字的键。
有什么函数可以把双引号补上去吗?注:json来源于其他网站,无法修改源json数据格式请帖代码,第一个通过得满分
string json="{
"data": {
"name": "test",
"sex": 1
";}
}"
JObject obj = JObject.Parse(json);
string name= (string)obj["data"]["name"]; //正常
string sex= (string)obj["data"]["sex"]; //sex的值为数字,且没有带双引号,错误现在就是不能取不带双引号,值为阿拉伯数字的键。
有什么函数可以把双引号补上去吗?注:json来源于其他网站,无法修改源json数据格式请帖代码,第一个通过得满分
"data": {
"birth_day": 3,
"birth_month": 11,
"birth_year": 1988,
"city_code": "",
"country_code": "1",
"edu": null,
"email": "[email protected]",
"fansnum": 15,
"head": "test",
"idolnum": 37,
"introduction": "",
"isent": 0,
"isrealname": 0,
"isvip": 0,
"location": "未知",
"name": "test",
"nick": "test",
"openid": "000",
"province_code": "31",
"sex": 2,
"tag": null,
"tweetnum": 499,
"verifyinfo": ""
},
"errcode": 0,
"msg": "ok",
"ret": 0
}
这个是腾讯微博API得到的数据
string name= (string)obj["data"]["name"]; //正常
string sex= (string)obj["data"]["sex"]; //sex的值为数字,且没有带双引号,错误报错为:Can not convert Integer to String.
改为
obj["data"]["sex"].ToString()