Trying to get the data in an array from my 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;
}
I want to get the title from the data array... How do I do this? this also does not work 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}
If you want to get the tags
as JSON Array, you can do the following
JObject response = context.GetOnePost(postmodel, token);
JArray array = JArray.Parse(response["data"]["tags"].ToString());
To get the title
and content
as string you do the following
JObject response = context.GetOnePost(postmodel, token);
PostModel post = new PostModel();
post.Title = response["data"]["title"].ToString();
post.Content = response["data"]["content"].ToString();
.
.
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.