[英]How to collect values for all the keys from a Dictionary<string,object> in a List
[英]How to write all keys and values within Dictionary<string, object> to a text file?
我有一个Dictionary<string, object> advertiserResponse
,看起来像这样......
"AdvertiserLookup": {
"Agency": {
"AgencyAlpha": "ABC",
"Media": [
{
"Code": "123",
"Name": "XYZ",
"Advertisers": {
"Advertiser": [
{
"Code": "JKL",
"Name": "EFG",
"BusinessKey": "HIJ"
},
{
"Code": "KLM",
"Name": "NOP",
"BusinessKey": "QRS"
},
{
这是我用来尝试写入文本文件的行:
File.WriteAllLines("test.txt", advertiserResponse.Select(x => "[" + x.Key + " " + x.Value + "]").ToArray());
我期待着Jason(在漂亮的印刷品中不是必需的 )以及AdvertiserLookup
下面的所有键和文本。 我在test.txt
得到了什么:
[AdvertiserLookup System.Collections.Generic.Dictionary``2[System.String,System.Object]]
如何将整个文章写入文本?
试试Json.NET吧。 您应该能够序列化您的字典。
var jsonString = JsonConvert.SerializeObject(advertiserResponse, Formatting.Indented)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.