从 IRestResponse 请求中读取数组

试图从我的数组中获取数据Jobject


public PostModel GetOnePost(PostModel postmodel, string token)

        {

            JObject response = context.GetOnePost(postmodel, token);


            PostModel post = new PostModel();

            post.Title = response.SelectToken("title").Value<string>();

            post.Content = response.SelectToken("content").Value<string>();

            post.Urgency = response.SelectToken("urgency").Value<string>();

            post.Slug = response.SelectToken("slug").Value<string>();

            post.Completed = response.SelectToken("completed").Value<bool>();

            return post;

        }

我想从数据数组中获取标题...我该怎么做?这也不起作用 response.SelectToken("data.title")


{{

  "success": true,

  "msg": "Post received",

  "data": {

    "postId": "91207a39-6faa-4372-86dc-c5aa6e9f720c",

    "title": "End me",

    "content": "please",

    "slug": "end-me",

    "urgency": "low",

    "completed": false,

    "createdAt": "2019-04-23T08:26:18.988Z",

    "updatedAt": "2019-04-23T08:26:18.988Z",

    "clientClientId": "f379f920-a6f9-45b0-95c8-5f91138fb7a5",

    "tags": []

  }

}}  Newtonsoft.Json.Linq.JToken {Newtonsoft.Json.Linq.JObject}


猛跑小猪
浏览 66回答 1
1回答

侃侃尔雅

如果你想获取tagsas JSON 数组,你可以执行以下操作JObject response = context.GetOnePost(postmodel, token);JArray array = JArray.Parse(response["data"]["tags"].ToString());要获取title和content作为字符串,您可以执行以下操作JObject response = context.GetOnePost(postmodel, token);PostModel post = new PostModel();post.Title = response["data"]["title"].ToString();post.Content = response["data"]["content"].ToString();...
打开App,查看更多内容
随时随地看视频慕课网APP