我需要通过resetsharp轻松地从这个json响应中获取值。变量"响应2"包含附带的json图片。我想获取" contactId"的单个值。从那个json。我已经尝试过" Headers"但是这说 - System.NullReferenceException:'对象引用没有设置为对象的实例。'我如何解决抓住" contactId"值?
var client2 = new RestClient("https://api.getresponse.com/v3/contacts?query[email]=test@gmail.com");
var request2 = new RestRequest(Method.GET);
request2.AddHeader("X-Auth-Token", "api-key 948dff90-my-key-f3c6");
request2.AddParameter("application/json", ParameterType.RequestBody);
var response2 = client2.Execute(request2);
string contactId = response2.Headers.ToList().Find(x => x.Name == "contactId").Value.ToString();
答案 0 :(得分:0)
您将在response2的Content属性中以字符串形式接收响应。 试试这个:
var obj = JsonConvert.DeserializeObject<dynamic>(response2.Content);
Console.WriteLine(obj[0].ContactId);