繁体   English   中英

从IRestResponse请求中读取数组

[英]Read array from IRestResponse request

试图从我的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}

如果要将tags作为JSON数组,可以执行以下操作

JObject response = context.GetOnePost(postmodel, token);
JArray array = JArray.Parse(response["data"]["tags"].ToString());

要将titlecontent作为字符串获取,请执行以下操作

JObject response = context.GetOnePost(postmodel, token);
PostModel post = new PostModel();
post.Title = response["data"]["title"].ToString();
post.Content = response["data"]["content"].ToString();
.
.
.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM