C
C
CityzenUNDEAD2021-07-11 13:51:21
JSON
CityzenUNDEAD, 2021-07-11 13:51:21

How to parse json where are fields with non-constant values?

Good afternoon!
I have the following json as a string

"numbers": {
    "9154857921": {
      "country": 7,
      "data_humans": "6 дней назад",
      "full_number": "+79154857921",
      "is_archive": false
    },
    "9600720935": {
      "country": 7,
      "data_humans": "3 дня назад",
      "full_number": "+79600720935",
      "is_archive": false
    },...
}


Judging by the info on the network, json is parsed using the Newtonsoft.Json library, where you need to prepare a special class for it with similar fields. But in the case above, json comes in where inside the numbers object there may be fields whose names cannot be known in advance. it will always be different numbers. How to parse this json in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-07-11
@CityzenUNDEAD

Numbers - dictionary. Where the key is a string, the value is a class that describes everything in the number. Something like:

class Person
{
public int country;
public string data_humans;
}

public Dictionary<string, Person> numbers;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question