.NET 4.x [Newtonsoft.Json] Парсинг JSON-ответа - C#
Формулировка задачи:
Здравствуйте уважаемые участники сообщества "CyberForum" !
У меня возникла небольшая проблема. Я перелопатил кучу форумов и 15 страниц "Google". Дело в том, что мне надо с JSON ответа выковыривать несколько значений, пример:
Мне нужны вытянуть отсюда значения: user_id или chat_id, body. Изасунуть их в массив.
Единственное что я смог написать это:
Заранее спасибо за ответ!
Листинг программы
- {
- "response":{
- "count":1158,
- "unread_dialogs":5,
- "items":[
- {
- "unread":247,
- "message":{
- "id":606897,
- "date":1441637552,
- "out":0,
- "user_id":261238234,
- "read_state":0,
- "title":"Вова, не трогай котикаф",
- "body":"рип ангел",
- "chat_id":60,
- "chat_active":[
- 143932243,
- 67463579,
- 89780064,
- 156305972,
- 219100799,
- 279883080,
- 278401247,
- 63978237,
- 236548043,
- 18128006,
- 172913248,
- 223386494,
- 151548290,
- 274091233,
- 275731093,
- 261238234,
- 272130632,
- 215948747,
- 115902960,
- 179462619,
- 310321856,
- 309337547,
- 132601651,
- 73369298,
- 197484075,
- 56490870,
- 314949237,
- 145607814,
- 230888230,
- 127010641,
- 97159873,
- 227957341,
- 316944318,
- 267394592,
- 296070568,
- 158701794,
- 307575713,
- 302530258,
- 274043557,
- 262464688,
- 322229680
- ],
- "push_settings":{
- "sound":0,
- "disabled_until":-1
- },
- "users_count":43,
- "admin_id":143932243,
- "photo_50":"https:\/\/pp.vk.me\/c623723\/v623723341\/3d431\/1eHfQXrtN68.jpg",
- "photo_100":"https:\/\/pp.vk.me\/c623723\/v623723341\/3d430\/g6mdJ3OiSi4.jpg",
- "photo_200":"https:\/\/pp.vk.me\/c623723\/v623723341\/3d42f\/0hfcii-i9sM.jpg"
- }
- },
- {
- "unread":288,
- "message":{
- "id":606850,
- "date":1441637232,
- "out":0,
- "user_id":243834389,
- "read_state":0,
- "title":"Песат какойта",
- "body":"",
- "attachments":[
- {
- "type":"photo",
- "photo":{
- "id":380631736,
- "album_id":-3,
- "owner_id":243834389,
- "photo_75":"https:\/\/pp.vk.me\/c622426\/v622426389\/3fa70\/iSW5omEuCU8.jpg",
- "photo_130":"https:\/\/pp.vk.me\/c622426\/v622426389\/3fa71\/hJDwVmDYEtY.jpg",
- "photo_604":"https:\/\/pp.vk.me\/c622426\/v622426389\/3fa72\/5sMHgSgrAfY.jpg",
- "width":296,
- "height":99,
- "text":"",
- "date":1441637232,
- "access_key":"297004d56320bc2227"
- }
- }
- ],
- "chat_id":75,
- "chat_active":[
- 156305972,
- 278401247,
- 219100799,
- 272130632,
- 223386494,
- 158701794,
- 276539367,
- 172913248,
- 279883080,
- 89780064,
- 155160916,
- 55475785,
- 67788426,
- 279508895,
- 306789926,
- 243834389,
- 135789959,
- 288352317,
- 270312149,
- 274091233,
- 90735275
- ],
- "push_settings":{
- "sound":0,
- "disabled_until":-1
- },
- "users_count":22,
- "admin_id":156305972,
- "photo_50":"https:\/\/pp.vk.me\/c622126\/v622126972\/4d4c7\/0W-ma1zZ3w4.jpg",
- "photo_100":"https:\/\/pp.vk.me\/c622126\/v622126972\/4d4c6\/CYKgzWjXf04.jpg",
- "photo_200":"https:\/\/pp.vk.me\/c622126\/v622126972\/4d4c4\/TXjRF68B0jI.jpg"
- }
- },
- {
- "message":{
- "id":606737,
- "date":1441633270,
- "out":0,
- "user_id":206579645,
- "read_state":1,
- "title":" ... ",
- "body":"Попробуй еще"
- }
- },
- {
- "message":{
- "id":606731,
- "date":1441633098,
- "out":1,
- "user_id":158021141,
- "read_state":1,
- "title":" ... ",
- "body":"В полную сили били?"
- }
- },
- {
- "message":{
- "id":606720,
- "date":1441632727,
- "out":1,
- "user_id":190661725,
- "read_state":0,
- "title":" ... ",
- "body":"Не , завтра приду , надо документы забрать"
- }
- }
- ]
- }
- }
Листинг программы
- public class PushSettings
- {
- public int sound { get; set; }
- public int disabled_until { get; set; }
- }
- public class Photo
- {
- public int id { get; set; }
- public int album_id { get; set; }
- public int owner_id { get; set; }
- public string photo_75 { get; set; }
- public string photo_130 { get; set; }
- public string photo_604 { get; set; }
- public int width { get; set; }
- public int height { get; set; }
- public string text { get; set; }
- public int date { get; set; }
- public string access_key { get; set; }
- }
- public class Attachment
- {
- public string type { get; set; }
- public Photo photo { get; set; }
- }
- public class Message
- {
- public int id { get; set; }
- public int date { get; set; }
- public int @out { get; set; }
- public int user_id { get; set; }
- public int read_state { get; set; }
- public string title { get; set; }
- public string body { get; set; }
- public int chat_id { get; set; }
- public List<int> chat_active { get; set; }
- public PushSettings push_settings { get; set; }
- public int users_count { get; set; }
- public int admin_id { get; set; }
- public string photo_50 { get; set; }
- public string photo_100 { get; set; }
- public string photo_200 { get; set; }
- public List<Attachment> attachments { get; set; }
- }
- public class Item
- {
- public int unread { get; set; }
- public Message message { get; set; }
- }
- public class Response
- {
- public int count { get; set; }
- public int unread_dialogs { get; set; }
- public List<Item> items { get; set; }
- }
- public class RootObject
- {
- public Response response { get; set; }
- }
Решение задачи: «.NET 4.x [Newtonsoft.Json] Парсинг JSON-ответа»
textual
Листинг программы
- public class PushSettings
- {
- public int sound { get; set; }
- public int disabled_until { get; set; }
- }
- public class Photo
- {
- public int id { get; set; }
- public int album_id { get; set; }
- public int owner_id { get; set; }
- public string photo_75 { get; set; }
- public string photo_130 { get; set; }
- public string photo_604 { get; set; }
- public int width { get; set; }
- public int height { get; set; }
- public string text { get; set; }
- public int date { get; set; }
- public string access_key { get; set; }
- }
- public class Attachment
- {
- public string type { get; set; }
- public Photo photo { get; set; }
- }
- public class Message
- {
- public int id { get; set; }
- public int date { get; set; }
- public int @out { get; set; }
- public int user_id { get; set; }
- public int read_state { get; set; }
- public string title { get; set; }
- public string body { get; set; }
- public int chat_id { get; set; }
- public List<int> chat_active { get; set; }
- public PushSettings push_settings { get; set; }
- public int users_count { get; set; }
- public int admin_id { get; set; }
- public string photo_50 { get; set; }
- public string photo_100 { get; set; }
- public string photo_200 { get; set; }
- public List<Attachment> attachments { get; set; }
- }
- public class Item
- {
- public int unread { get; set; }
- public Message message { get; set; }
- }
- public class Response
- {
- public int count { get; set; }
- public int unread_dialogs { get; set; }
- public List<Item> items { get; set; }
- }
- public class RootObject
- {
- public Response response { get; set; }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д