伪代码
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数据格式请帖代码,第一个通过得满分

解决方案 »

  1.   

    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
    }
      

  2.   

    值为数字的,取值就有问题
    这个是腾讯微博API得到的数据
      

  3.   

    取值 JObject obj = JObject.Parse(json);
     string name= (string)obj["data"]["name"]; //正常
     string sex= (string)obj["data"]["sex"]; //sex的值为数字,且没有带双引号,错误报错为:Can not convert Integer to String. 
      

  4.   

    (string)obj["data"]["sex"]
    改为
    obj["data"]["sex"].ToString()