D
D
DeNyd2021-08-08 13:27:10
C++ / C#
DeNyd, 2021-08-08 13:27:10

How to pull specific data from json file?

Hello, I have this json file:

{
  "relationships_followers": [
    {
      "title": "",
      "media_list_data": [
        
      ],
      "string_list_data": [
        {
          "href": "https://www.instagram.com/20rozok02",
          "value": "20rozok02",
          "timestamp": 1607203051
        }
      ]
    },
    {
      "title": "",
      "media_list_data": [
        
      ],
      "string_list_data": [
        {
          "href": "https://www.instagram.com/ildar.yusupov.1990",
          "value": "ildar.yusupov.1990",
          "timestamp": 1606909478
        }
      ]
    },
    {
      "title": "",
      "media_list_data": [
        
      ],
      "string_list_data": [
        {
          "href": "https://www.instagram.com/aitmahan.ernur",
          "value": "aitmahan.ernur",
          "timestamp": 1589734471
        }
      ]
    },
    {
      "title": "",
      "media_list_data": [
        
      ],
      "string_list_data": [
        {
          "href": "https://www.instagram.com/blyagafarov",
          "value": "blyagafarov",
          "timestamp": 1586728175
        }
      ]
    }
  ]
}


How can I extract all the values ​​of the value variable from the json file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Foggy Finder, 2021-08-08
@DeNyd

One way (Linq2Json), using the Json.Net library , which edward_freedom wrote about in the comments.

var jsonPath = "data.json";
using StreamReader reader = File.OpenText(jsonPath);
var jToken = JToken.ReadFrom(new JsonTextReader(reader));
            
var values =
    jToken["relationships_followers"].Select(j =>
            j["string_list_data"][0]["value"].ToObject<string>())
    .ToArray();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question