Это мой третий ответ для вас. Я надеюсь, что вы можете ответить мне, чтобы узнать, поможет ли это вам или нет. :)
аюсь взять значения, которые я проанализировал, из файла JSON и преобразовать их в строки. Я пробовал всю неделю, но до сих пор не могу понять это.
Мой текущий вывод выглядит так:
a: 1
b: 2
c: 3
a: 1a
b: 2a
c: 3a
a: 1b
b: 2b
c: 3b
Я хочу, чтобы мой вывод был таким, но я не могу найти решение.
a b c
1 2 3
1a 2a 3a
1b 2g 3b
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
string json =
@"{
'somethingone': 'abc',
'somethingtwo': 'abcde-1234',
'information':
{
'report': [
{
'a': '1',
'b': '2',
'c': '3'
},
{
'a': '1a',
'b': '2a',
'c': '3a'
},
{
'a': '1b',
'b': '2b',
'c': '3b'
},
]
}
}";
RootObj mainObj = JsonConvert.DeserializeObject<RootObj>(json);
Console.WriteLine("somethingone: " + mainObj.somethingone);
Console.WriteLine("somethingtwo: " + mainObj.somethingtwo);
foreach (Dictionary<string, string> report in mainObj.information.report)
{
foreach (KeyValuePair<string, string> item in report)
{
string key = item.Key;
string value = item.Value;
Console.WriteLine(key + ": " + value);
}
}
}
}
class RootObj
{
public string somethingone { get; set; }
public string somethingtwo { get; set; }
public Information information { get; set; }
}
class Information
{
public Dictionary<string, string>[] report { get; set; }
}