Hasan Kaan TURAN
Hasan Kaan TURAN

Reputation: 361

Read data from a JSON file

I have a JSON file out of the custom JSON pattern. And I need get this string values with array, list or anything.

example.json:

[
   ["fight", "gunshot", "fleeing"], 
   ["gunshot", "falling", "fleeing"] 
]   

Upvotes: -1

Views: 160

Answers (1)

errorau
errorau

Reputation: 2334

If you use @Jimi option like that

First

using Newtonsoft.Json;
using System.Collections.Generic;

Then

string myJsonString = @"[['fight', 'gunshot', 'fleeing'], ['gunshot', 'falling', 'fleeing']]";
List<List<string>> items = JsonConvert.DeserializeObject<List<List<string>>>(myJsonString );

Console.Write(items[0][0]);

foreach (var item in items)
{
    foreach(var subitem in item){
        Console.WriteLine(subitem);
    }
}

also here is working version this code maybe you can create a simular stack app then share with us. https://dotnetfiddle.net/oKUUxa

Upvotes: 2

Related Questions