我在將JSON反序列化爲對象時遇到問題。我讀了幾個答案,但他們都沒有幫助我。
這是我的JSON文件:將JSON反序列化爲.net對象
{
"meta": {
"status": 200,
"msg": "OK"
},
"response": {
"blog": {
"title": "title",
"name": "name",
"url": "url"
}
}
}
這是我的課:
public class TextInfo
{
public class Meta
{
public int status { get; set; }
public string msg { get; set; }
}
public class Blog
{
public string title { get; set; }
public string name { get; set; }
public string url { get; set; }
}
public class Response
{
public Blog blog { get; set; }
}
public class RootObject
{
public Meta meta { get; set; }
public Response response { get; set; }
}
}
現在,我試圖反序列化,像這樣的JSON,但我不知道如何操作數據:
TextInfo txt = JsonConvert.DeserializeObject<TextInfo>(json);
你能幫我弄清楚這個嗎?提前致謝。
*但我不知道如何操縱數據*這是什麼意思? –
例如,我想在一個數據庫中存儲博客名稱,我不知道如何從「txt」獲取該博客名稱 – Garnyatar
您的意思是'textInfo.response.blog.name'?請注意,您應該使用.NET命名約定,您目前不是。屬性應該是PascalCase。 –