[英]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());
要將title
和content
作為字符串獲取,請執行以下操作
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.