0
지도는 lib : Json.NET으로 작업하고 있습니다. 는 내가 JSON 파일을 역 직렬화 할 수 있지만 내가 "의 값에 액세스 할 수있는 방법을 클래스의 속성 json.net의 알 수없는 속성
public class Product
{
[JsonExtensionData]
private IDictionary<string, JToken> _additionalData { get; set; }
}
public class MyData
{
public Product Product { get; set; }
}
------main programme ----
using (StreamReader r = new StreamReader(@"\Base File\Base.json"))
{
json = r.ReadToEnd();
MyData invoice = JsonConvert.DeserializeObject<MyData>(json);
string result = JsonConvert.SerializeObject(invoice);
}
에 JSON 속성을 매핑 할 수 없습니다
{
"Product":
{
"random Key1": "some text",
"random Key2": "some text",
"random Key3": "some text"
},
"TestSequence":
{
"random Key4": "Some text"
}
}
아래의 데이터가있는 JSON 파일이 임의의 Key1 "속성을 내 코드에서? 값을 액세스하기 위해 물론
var invoice = JsonConvert.DeserializeObject<MyData>(json);
foreach (var item in invoice.Product)
{
Console.WriteLine("key: {0}, value: {1}", item.Key, item.Value);
}
: 모든 키와 값을 통해 당신은 루프 수 역 직렬화하면 다음
public class MyData
{
public IDictionary<string, string> Product { get; set; }
}
과 :
(속성 이름이 키가 됨) 또는 사용자 지정 변환기를 구현합니다 – Plutonix