从IRestResponse请求读取数组

时间:2019-04-23 09:46:49

标签: c# asp.net json

试图从我的//div[text()='Jong'] //div[.='Jong'] //div[@class='b-list-item' and text()='Jong'] 中获取数组中的数据

Jobject

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

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

1 个答案:

答案 0 :(得分:0)

如果要获取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();
.
.
.