I am trying to present an unknown JSON with TreeView. I will also need to edit the string inside these JSON objects and write them back so I need some form of a dictionary but the keys can repeat from one side of hierarchy to the other ("response" in the JSON example). I've researched and researched but I am unable to find something that works. Most of the questions are also asked for winforms or without use of MVVM which I'm unable to translate to what I am after.
JSON example:
{
"universal": {
"regionalSettings": {
"culture": {
"en-GB": "United Kingdom (en-GB)",
"mk-MK": "Македонија (mk-MK)",
"sq-MK": "Shqipëria (sq-MK)",
},
"language": {
"en-GB": "English (United Kingdom)",
"mk": "Македонски",
"sq": "Shqipe",
},
"timeZone": {
"Europe/Amsterdam": "Europe/Amsterdam",
"Europe/Andorra": "Europe/Andorra",
"Europe/Astrakhan": "Europe/Astrakhan",
"Europe/Athens": "Europe/Athens",
"Europe/Belgrade": "Europe/Belgrade",
"Europe/Berlin": "Europe/Berlin",
"Europe/Bratislava": "Europe/Bratislava",
"Europe/Brussels": "Europe/Brussels",
}
}
}
}
View snippet:
<ScrollViewer>
<TreeView>
<HierarchicalDataTemplate ItemsSource="{Binding Tree}" />
</TreeView>
</ScrollViewer>
ViewModel snippet:
public class SomeViewModel
{
public JToken Tree { get; set; }
private void PopulateTreeView()
{
var jsonReader = new JsonReader();
var jsonText = jsonReader.Read("C:\\imaginary_path\\example.json");
var token = JToken.Parse(jsonText);
// where magic should happen
Tree = token;
}
}
"where magic should happen" marks where I'm missing code. There I need to somehow hierarchically represent the json and make in into a format that I can pass into TreeView and at the same time also include strings (in the object, not in the TreeView itself as I will need to display those strings when particular item in a tree is selected), currently I'm passing JObject which makes the TreeView display root that says "System.Windows.HierarchicalDataTemplate".
I am sincerely thanking everyone that can help in advance.
