且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从C#中的Json字符串中检索值

更新时间:2023-02-23 08:58:18

这是一个小型控制台应用程序,显示了如何使用Json.NET检索它.在您的情况下,将从响应中检索字符串"json".

Here's a small console application showing how you'd retrieve it using Json.NET. In your case the string, "json" would be retrieved from the response.

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);
}