2
嗨,大家好,这是源JASON:解析嵌套的JSON在C#
{
"is_error":0,
"undefined_fields":["custom"],
"version":3,
"count":1,
"id":15862,
"values":{
"15862":{
"id":15862,
"contact_type":"Individual",
"contact_sub_type":null,
"do_not_email":null,
"do_not_phone":null,
"do_not_mail":null,
"do_not_sms":null,
"do_not_trade":null,
"is_opt_out":null,
"legal_identifier":null,
"external_identifier":null,
"sort_name":"last, first",
"display_name":"first last",
"nick_name":null,
"legal_name":null,
"image_URL":null,
"preferred_communication_method":null,
"preferred_language":"en_US",
"preferred_mail_format":null,
"hash":"2b",
"api_key":"eb",
"first_name":"Frist",
"middle_name":"A.",
"last_name":"Last",
"prefix_id":null,
"suffix_id":null,
"email_greeting_id":null,
"email_greeting_custom":null,
"email_greeting_display":null,
"postal_greeting_id":null,
"postal_greeting_custom":null,
"postal_greeting_display":null,
"addressee_id":null,
"addressee_custom":null,
"addressee_display":null,
"job_title":"Title",
"gender_id":null,
"birth_date":null,
"is_deceased":null,
"deceased_date":null,
"household_name":null,
"primary_contact_id":null,
"organization_name":"OrgName",
"sic_code":null,
"user_unique_id":null
}
}
}
我有两个问题。正如您可以看到每次返回响应时定义“值”下的数字键,第二,我似乎无法访问“值”键内的任何内容。
我已经attemped使用JSON.Net但我得到:
无法转换类型“Newtonsoft.Json.Linq.JObject”的对象键入“Newtonsoft.Json.Linq.JArray”。
使用:
JObject o = JObject.Parse(json);
JArray values = (JArray)o["values"];
去最里面的数据(这是我所关心的),但我的一切,为了试图让过去的响应不工作的根级别.. 。 你有什么想法?
是的,“值”不是一个数组,它是另一个属性。如果它是一个数组,它会是:values:[/ * stuff here * /]; – Jonas
感谢您的回复,我尝试了JavaScriptSerializer,并且遇到了一些麻烦。以下是我遇到的内容:http://stackoverflow.com/questions/7870307/runtime-binder-exception-was-unhandled-c-sharp-json-deserialization-temtemptne – Derek