[英]How to retrieve value from Json string in C#
I'm getting a response like 我得到像这样的回应
{ "expires": "Sat, 19 May 2046 04:10:58 +0000", "copy_ref": "SMJNA2wxbGZbnmbnm", "Result": null, "error": null }
base: { "expires": "Sat, 19 May 2046 04:10:58 +0000", "copy_ref": "SMJNA2wxbGZ0aWRibWw2aA", "Result": null, "error": null }
ContentDisposition: null
ContentType: "application/json"
HttpHeaders: {Connection: keep-alive
expires=Tue, 25 May 2021 04:10:58 GMT;
}
IsArray: true
IsSuccessfully: true
IsXml: true
Result: { "expires": "Sat, 19 May 2046 04:10:58 +0000", "copy_ref": "SMJNA2wxbGZbnmbnm", "Result": null, "error": null }
StatusCode: 200
I need the value of "copy_ref" from this response string in C#. 我需要C#中此响应字符串的“ copy_ref”值。
Here's a small console application showing how you'd retrieve it using Json.NET. 这是一个小型控制台应用程序,显示了如何使用Json.NET检索它。 In your case the string, "json" would be retrieved from the response. 在您的情况下,将从响应中检索字符串“ json”。
static void Main()
{
string json = @"
{ 'expires': 'Sat, 19 May 2046 04:10:58 + 0000', 'copy_ref': 'SMJNA2wxbGZbnmbnm', 'Result': null, 'error': null }";
JObject jObj = JObject.Parse(json); // Parse the object graph
string copyRef = jObj["copy_ref"].ToString(); // Retrive value by key
Console.WriteLine(copyRef);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.