Cześć Mam json, który wygląda tak:Get wartości i klucze w obiekcie json używając Json.Net C#
{
"Id": " 357342524563456678",
"title": "Person",
"language": "eng",
"questionAnswer": [
{
"4534538254745646.1": {
"firstName": "Janet",
"questionNumber": "1.1"
}
}
]
}
Teraz Pisałem jakiś kod, który obwodów nad obiektami w tablicy questionAnswer
a następnie pobiera nazwa obiektu, który jest 4534538254745646.1
. Teraz próbuję zapisać klucz każdego przedmiotu i jego wartość, ale tylko staram się uzyskać wartość.
Jak to zrobić, tutaj jest mój kod:
JToken entireJson = JToken.Parse(json);
JArray inner = entireJson["questionAnswer"].Value<JArray>();
foreach(var item in inner)
{
JProperty questionAnswerDetails = item.First.Value<JProperty>();
//This line gets the name, which is fine
var questionAnswerSchemaReference = questionAnswerDetails.Name;
var properties = questionAnswerDetails.Value.First;
//This only gets Janet
var key = properties.First;
var value = properties.Last;
}
Więc w tym momencie Im tylko w stanie dostać się Janet, ale chcę też pole firstname. Chcę następnie wziąć to i dodać do słownika tj
Dictionary<string, string> details = new Dictionary<string, string>();
//suedo
foreach(var item in questionAnswerObjects)
details.Add(firstName, Janet);
//And then any other things found below this