Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用JSON数组进行RestSharp反序列化(Null)_C#_Json_List_Deserialization_Restsharp - Fatal编程技术网

C# 使用JSON数组进行RestSharp反序列化(Null)

C# 使用JSON数组进行RestSharp反序列化(Null),c#,json,list,deserialization,restsharp,C#,Json,List,Deserialization,Restsharp,我在尝试将json数组反序列化为.NET POCO对象时遇到了挑战 下面是我生成的POCO类(我使用了json2csharp): 以下是我如何称呼RestSharp的: var request = new RestRequest("api/now/table/incident", Method.GET) { RequestFormat = DataFormat.Json }; var response = client.Execute<RootObjectList>(request

我在尝试将json数组反序列化为.NET POCO对象时遇到了挑战

下面是我生成的POCO类(我使用了json2csharp):

以下是我如何称呼RestSharp的:

var request = new RestRequest("api/now/table/incident", Method.GET) { RequestFormat = DataFormat.Json };

var response = client.Execute<RootObjectList>(request);

if (response.Data == null)
   throw new Exception(response.ErrorMessage);
var-request=new-RestRequest(“api/now/table/incident”,Method.GET){RequestFormat=DataFormat.Json};
var response=client.Execute(请求);
if(response.Data==null)
抛出新异常(response.ErrorMessage);
我得到的错误信息是:

无法将“System.String”类型的对象强制转换为“System.Collections.Generic.IDictionary`2[System.String,System.object]”类型


我也试过阅读其他几个stackoverflow帖子,但都没有成功。如果有人能帮忙,我将不胜感激祝你今天愉快

这是一个巨大的JSON。您应该努力将其最小化到导致错误的部分。我可以使用
SimpleJson.DeserializeObject(JSON)
成功地反序列化问题中的JSON字符串。这表明你收到的回应不是你所想的;也许是某种短信?谢谢你,尤瓦尔。是的,这只是实际返回的JSON的一个片段。我认为手头的第一个议程是在列表中查找导致此错误的违规结果对象,但是这很困难,因为结果计数是在数千个结果对象中。我还尝试了这行代码,但没有成功:request.OnBeforeDeserialization=resp=>{resp.ContentType=“application/json”;};我仍在试图弄清楚这个错误的确切含义。我认为有问题的json属性是“u_first_assigned_to”,它将返回两个可能的值:“u_first_assigned_to”:{“link”:“somevaluehere”,“value”:“990947696F63210000CA5D02BEEE408”或“u first_assigned_to”:我将如何为此创建一个类,以便它接受这两种类型的值?看起来我解决了我的问题。分配给{get;set;}的公共字符串u_first_应该是分配给{get;set;}的公共对象u_first_
{"result":[{"skills":"","u_technical_service":"","urgency":"1","correlation_id":"","u_assigned_above_tier_1":"false","u_business_service":"","group_list":"","follow_up":"","closed_at":"2015-02-17 23:43:26","parent":"","number":"INC0000101","closed_by":{"link":"https://some url","value":"6816f79cc0a8016401c5a33be04be441"},"work_start":"","calendar_stc":"5283743","incident_state":"7","category":"inquiry","business_duration":"1970-01-15 14:43:26","u_resolve_code":"","correlation_display":"","due_date":"","u_first_level_resolvable":"false","knowledge":"false","made_sla":"false","comments_and_work_notes":"","u_incident_dashboard":"false","user_input":"","u_first_call_resolution":"false","rfc":"","u_sla_due":"","child_incidents":"","u_first_assigned_to":"","u_incident_model":"","upon_reject":"cancel","u_set_to_p1":"","approval_history":"","u_template":"","work_notes":"","u_reopened":"false","u_in_stock":"","sys_id":"ccefe8620a0006d400b6b6e1beec71d7","u_affected_user":"","u_major_incident":"false","u_test_alex2":"","sys_created_by":"admin","business_stc":"1262606","subcategory":"","u_actual_start_date":"","contact_type":"phone","time_worked":"","u_kb_article":"","comments":"","upon_approval":"proceed","u_resolving_company":"","u_old_number":"","location":{"link":"someurl","value":"db9a923c0a0a0a6501068d6eaec25ee0"},"expected_start":"","reopen_count":"","u_schedule":"","close_notes":"Done","u_asset_redeployable":"","service_offering":"","impact":"1","priority":"2","description":"","sys_domain":{"link":"https:someurl","value":"global"},"u_on_hold_type":"","sys_mod_count":"9","work_notes_list":"","u_actual_end_date":"","u_cancelled_sub_state":"","sla_due":"","u_priority_down":"","sys_updated_on":"2015-02-18 00:16:58","u_critical_outage_communicatio":"","work_end":"","u_protocol_not_followed":"false","activity_due":"","company":"","active":"false","u_created_by_tier_1":"false","u_sub_state":"1","assignment_group":{"link":"someurl","value":"d625dccec0a8016700a222a0f7900d06"},"caller_id":{"link":"someurl","value":"9ee1b13dc6112271007f9d0efdb69cd0"},"parent_incident":"","state":"7","approval_set":"","sys_created_on":"2014-12-18 20:02:23","reassignment_count":"0","u_lateral_assignment":"false","u_attached_knowledge":"","u_symptom":"","opened_at":"2014-12-18 20:01:03","order":"","short_description":"Bond Trading app is not available","u_incident_state_count":"","resolved_by":"","sys_updated_by":"Timothy_Woodruff","notify":"1","u_priority_up":"","problem_id":"","calendar_duration":"1970-03-03 03:42:23","close_code":"Solved (Work Around)","approval":"not requested","caused_by":"","severity":"3","u_kb_solution_steps":"","resolved_at":"","assigned_to":"","u_sla_met":"","cmdb_ci":{"link":"someurl","value":"250b0f530a0a0b1d00b60acc42ff36a6"},"opened_by":{"link":"someurl","value":"6816f79cc0a8016401c5a33be04be441"},"sys_class_name":"incident","u_first_line_resolved":"false","watch_list":"","escalation":"0","u_device_asset_name":"","u_open_url":""},{"skills":"","u_technical_service":"","urgency":"1","correlation_id":"","u_assigned_above_tier_1":"false","u_business_service":"","group_list":"","follow_up":"","closed_at":"2015-02-17 23:43:27","parent":"","number":"INC0000102","closed_by":{"link":"someurl","value":"6816f79cc0a8016401c5a33be04be441"},"work_start":"","calendar_stc":"3362","incident_state":"7","category":"inquiry","business_duration":"1970-01-01 00:56:02","u_resolve_code":"","correlation_display":"","due_date":"","u_first_level_resolvable":"false","knowledge":"false","made_sla":"true","comments_and_work_notes":"","u_incident_dashboard":"false","user_input":"","u_first_call_resolution":"false","rfc":"","u_sla_due":"","child_incidents":"","u_first_assigned_to":"","u_incident_model":"","upon_reject":"cancel","u_set_to_p1":"","approval_history":"","u_template":"","work_notes":"","u_reopened":"false","u_in_stock":"","sys_id":"cd5149720a0006d400a0bc76eccf54cc","u_affected_user":"","u_major_incident":"false","u_test_alex2":"","sys_created_by":"admin","business_stc":"3362","subcategory":"","u_actual_start_date":"","contact_type":"phone","time_worked":"","u_kb_article":"","comments":"","upon_approval":"proceed","u_resolving_company":"","u_old_number":"","location":{"link":"someurl","value":"db9a923c0a0a0a6501068d6eaec25ee0"},"expected_start":"","reopen_count":"","u_schedule":"","close_notes":"Done","u_asset_redeployable":"","service_offering":"","impact":"1","priority":"1","description":"","sys_domain":{"link":"someurl","value":"global"},"u_on_hold_type":"","sys_mod_count":"4","work_notes_list":"","u_actual_end_date":"","u_cancelled_sub_state":"","sla_due":"","u_priority_down":"","sys_updated_on":"2015-02-17 23:43:27","u_critical_outage_communicatio":"","work_end":"","u_protocol_not_followed":"false","activity_due":"2015-02-18 00:49:35","company":"","active":"false","u_created_by_tier_1":"false","u_sub_state":"","assignment_group":{"link":"someurl","value":"d625dccec0a8016700a222a0f7900d06"},"caller_id":{"link":"someurl","value":"9ee1b13dc6112271007f9d0efdb69cd0"},"parent_incident":"","state":"7","approval_set":"","sys_created_on":"2015-02-17 22:48:01","reassignment_count":"0","u_lateral_assignment":"false","u_attached_knowledge":"","u_symptom":"","opened_at":"2015-02-17 22:47:25","order":"","short_description":"App is not visible","u_incident_state_count":"","resolved_by":"","sys_updated_by":"admin","notify":"1","u_priority_up":"","problem_id":"","calendar_duration":"1970-01-01 00:56:02","close_code":"Solved (Work Around)","approval":"not requested","caused_by":"","severity":"3","u_kb_solution_steps":"","resolved_at":"","assigned_to":"","u_sla_met":"","cmdb_ci":{"link":"https://somerul","value":"250b0f530a0a0b1d00b60acc42ff36a6"},"opened_by":{"link":"someurl","value":"6816f79cc0a8016401c5a33be04be441"},"sys_class_name":"incident","u_first_line_resolved":"false","watch_list":"","escalation":"0","u_device_asset_name":"","u_open_url":""}]}
var request = new RestRequest("api/now/table/incident", Method.GET) { RequestFormat = DataFormat.Json };

var response = client.Execute<RootObjectList>(request);

if (response.Data == null)
   throw new Exception(response.ErrorMessage);