我有字典。
Dictionary<string, List<string>>
我使用此行序列化了该对象;
var ss = JsonConvert.SerializeObject(objDic, Formatting.Indented);
JSON有效!
{
"keywords a": [
"keywords analytics,",
"keywords abstract,",
"keywords amazon,",
"keywords anywhere,",
"keywords adwords,",
"keywords architecture,",
"keywords apa,",
"keywords app store,",
"keywords and seo,",
"keywords armor,"
],
"keywords b": [
"keywords book,",
"keywords bidding,",
"keywords broad match,",
"keywords blog,",
"keywords business,",
"keywords book pdf,",
"keywords by country,",
"keywords by industry,",
"keywords bridge,",
"keywords bidding strategy,"
],
"keywords c": [
"keywords creator,",
"reserved keywords c,",
"keywords c#,",
"keywords combo list,",
"keywords cv,",
"keywords checker,",
"keywords check,",
"keywords css,",
"keywords computer,",
"keywords consulting resume,"
],
"keywords d": [
"keywords definition,",
"keywords density checker,",
"keywords definition in c,",
"keywords density,",
"keywords dublin,",
"keywords density formula,",
"keywords digital marketing,",
"keywords design,",
"keywords def,",
"keywords database,"
],
"keywords e": [
"keywords everywhere,",
"keywords explorer,",
"keywords ekleme,",
"keywords everywhere chrome,",
"keywords essay,",
"english keywords,"
],
"keywords f": [
"keywords finder,",
"keywords for amazon,",
"keywords for fluency intermediate pdf,",
"keywords for fluency pre intermediate pdf,",
"keywords for youtube,",
"keywords for slayer leecher,",
"keywords for seo,",
"keywords for present perfect,",
"keywords for resume,",
"keywords for generator,"
],
"keywords g": [
"keywords generator,",
"keywords google,",
"keywords google seo,",
"keywords google play,",
"keywords google analytics,",
"keywords google adwords tool,",
"keywords google adwords,",
"keywords gwent,",
"keywords good,",
"keywords google free,"
],
"keywords h": [
"keywords html,",
"keywords history,",
"keywords how to seo,",
"keywords human resources,",
"keywords high cpc,",
"keywords how many,",
"keywords hearthstone,",
"keywords how to write,",
"keywords hq,",
"keywords halloween,"
],
"keywords i": [
"keywords io,",
"keywords international,",
"keywords in java,",
"keywords in c,",
"keywords in python,",
"keywords imdb,",
"keywords in html,",
"keywords in sql,",
"keywords index medicus,",
"keywords in seo,"
],
"keywords j": [
"keywords java,",
"keywords javascript,",
"keywords jobs,",
"keywords journal,",
"keywords job search,",
"keywords john patrick leary,",
"keywords jewelry,",
"keywords japan,",
"keywords jeet,",
"keywords job application,"
],
"keywords k": [
"keywords kullanımı,",
"keywords kindle,",
"keywords kdp,",
"keywords key words,",
"keywords kotlin,",
"keywords keywords tool,",
"keywords kostenlos finden,",
"custom keywords katalon,",
"keywords. try more general keywords,",
"how are negative keywords different from other keywords,"
],
"keywords l": [
"keywords list,",
"keywords latex,",
"keywords linkedin,",
"keywords lightroom,",
"keywords localization,",
"keywords like as like and is are often used when what type of context clue is used,",
"keywords leary,",
"keywords logo,",
"keywords length seo,",
"keywords list in java,"
],
"keywords m": [
"keywords meta,",
"keywords mesh,",
"keywords meta tag,",
"keywords maker,",
"keywords meaning,",
"keywords montreal,",
"keywords marketing,",
"keywords minecraft,",
"keywords mysql,",
"keywords magic the gathering,"
],
"keywords n": [
"keywords ne demek,",
"keywords nedir,",
"keywords nasıl yazılır,",
"keywords nasıl olmalı,",
"keywords netflix,",
"keywords netflix slayer leecher,",
"keywords neil patel,",
"keywords nature,",
"keywords number of searches,",
"keywords node js,"
],
"keywords o": [
"keywords or key words,",
"keywords oluşturucu,",
"keywords of present simple,",
"keywords of past continuous,",
"keywords of present continuous,",
"keywords of present perfect,",
"keywords on youtube,",
"keywords of java,",
"keywords of c++,",
"keywords of mysql,"
],
"keywords p": [
"keywords planner,",
"keywords present perfect,",
"keywords past continuous,",
"keywords present continuous,",
"keywords present simple,",
"keywords past simple,",
"keywords present perfect continuous,",
"keywords past perfect,",
"keywords planner tool,",
"keywords planner google,"
],
"keywords q": [
"keywords qa,",
"keywords quality score,",
"keywords quotes,",
"keywords questions,",
"keywords quizlet,",
"keywords que es,",
"keywords quality assurance,",
"keywords que son,",
"keywords que es en español,",
"keywords quantitative research,"
],
"keywords r": [
"keywords research,",
"keywords resume,",
"keywords research tool,",
"keywords ranking,",
"keywords research google,",
"keywords research paper,",
"keywords research free,",
"keywords revealer,",
"keywords related to books,",
"keywords related to bpo,"
],
"keywords s": [
"keywords studios,",
"keywords seo,",
"keywords search,",
"keywords studios ekşi,",
"keywords studios katowice,",
"keywords slayer leecher,",
"keyword shitter,"
],
"keywords t": [
"keywords tool,",
"keywords tool youtube,",
"keywords türkçe anlamı,",
"keywords tool google,",
"keywords tools google,",
"keywords tool adwords,",
"keywords tool google adwords,",
"keywords trend google,",
"keywords travel,",
"keywords target audience,"
],
"keywords u": [
"keywords used in exception handling,",
"keywords used in java,",
"keywords used in python,",
"keywords used in exception handling in c++,",
"keywords upsc,",
"keywords usage test,",
"keywords used in c++,",
"keywords used,",
"keywords used in resume,",
"keywords used by recruiters,"
],
"keywords v": [
"keywords volume checker,",
"keywords vs tags,",
"keywords vs key words,",
"keywords vs reserved words,",
"keywords vs search terms,",
"keywords vision ias,",
"keywords video,",
"keywords value,",
"keywords vs adwords,",
"keywords vmc,"
],
"keywords w": [
"keywords wrapper,",
"keywords with peter and jane,",
"keywords wordpress,",
"keywords website,",
"keywords williams,",
"keywords wikipedia,",
"keywords with high cpc,",
"keywords with ladybird,",
"keywords with +,",
"keywords wordstream,"
],
"keywords x": [
"keywords xing,",
"keywords xtreme,",
"keywords xenapp,",
"keywords xenapp 6.5,",
"keywords xhtml,",
"keywords xmp,",
"keywords xml,",
"top keywords xing,",
"adobe bridge keywords xml,",
"pdf keywords xmp,"
],
"keywords y": [
"keywords youtube,",
"keywords yoast seo,",
"keywords youtube videos,",
"keywords yoga,",
"keywords yoast,",
"keywords yii2,",
"keywords your searches used,",
"keywords youtube channel,",
"keywords youtube tags,",
"keywords youtube free,"
]
}
下一行是这个。
var gg = JsonConvert.DeserializeObject<string>(ss);
在该行中,出现如下错误。
解析值{时遇到意外字符。路径“,行 1,位置1。
好的。我也试过了。
var gg = JsonConvert.DeserializeObject<List<string>>(ss);
注意List<string>.
我收到此错误。
无法反序列化当前JSON对象(例如{“ name”:“ value”}) 变成'System.Collections.Generic.List`1 [System.String]'类型,因为 该类型需要JSON数组(例如[1,2,3])进行反序列化 正确地。要解决此错误,请将JSON更改为JSON数组 (例如[1,2,3])或更改反序列化类型,使其成为常规 .NET类型(例如,不是整数之类的原始类型,不是集合 可以从JSON反序列化的类型(如数组或列表) 宾语。也可以将JsonObjectAttribute添加到类型中以强制它 从JSON对象反序列化。
我想反序列化您在上方看到的代码回到Dictionary<string, List<string>>
非常感谢您。
答案 0 :(得分:5)
您正在尝试将Dictionary<string, List<string>>
的json反序列化为string
。尝试以下方法:
var gg = JsonConvert.DeserializeObject<Dictionary<string, List<string>>(ss);
编辑
我测试了以下内容,没有任何问题:
public void Test()
{
test = new Dictionary<string, List<string>>();
test.Add("1", new List<string>() { "a", "b", "c" });
test.Add("2", new List<string>() { "a", "b", "c" });
test.Add("3", new List<string>() { "a", "b", "c" });
test.Add("4", new List<string>() { "a", "b", "c" });
test.Add("5", new List<string>() { "a", "b", "c" });
string json = JsonConvert.SerializeObject(test, Formatting.Indented);
Dictionary<string, List<string>> deserialized = JsonConvert.DeserializeObject<Dictionary<string, List<string>>>(json);
}