Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a Json model that looks like this

private class SearchMetadataJson
{
      public string entertain { get; set; }
      public string master { get; set; }
      public string memail { get; set; }
      public string key { get; set; }
      public (int, string)[] mood { get; set; }
      public int? soundnumber { get; set; }
      public int? ftv { get; set; }
      public int? com { get; set; }
      public (int, string)[] sims { get; set; }
      public (int, string)[] keysecond { get; set; }
      public string popt { get; set; }
      public (string, string) syncs { get; set; }
 }

And I try to de-serialize the object like this

var CommentObj = JsonSerializer.Deserialize<SearchMetadataJson>(CommentAsString);

The data that I'm trying to de-serialize (aka "CommentAsString") looks like this

"{"entertain":"PEG","master":"Phos Ent Group","memail":"example@example.com","key":"Db","mood":{"1":"TypeA","4":"TypeB","5":"TypeC"},"soundnumber":"5","ftv":"4","com":"3","sims":{"1":"Band1","2":"Band2"},"keysecond":{"1":"KeyWord1","2":"KeyWord2","3":"KeyWord3"},"syncs":{"Other pubber":"example2@example.com"}}"

But I keep getting this error
enter image description here

Does anyone see what the problem is?

Update
The integers in CommentAsString are variables and will be different every time the function is called so I can't make a Json Object that has a key value of a particular integer.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

Lets look at the actual formatted data structure

{
   "entertain":"PEG",
   "master":"Phos Ent Group",
   "memail":"example@example.com",
   "key":"Db",
   "mood":{
      "1":"TypeA",
      "4":"TypeB",
      "5":"TypeC"
   },
   "soundnumber":"5",
   "ftv":"4",
   "com":"3",
   "sims":{
      "1":"Band1",
      "2":"Band2"
   },
   "keysecond":{
      "1":"KeyWord1",
      "2":"KeyWord2",
      "3":"KeyWord3"
   },
   "syncs":{
      "Other pubber":"example2@example.com"
   }
}

Converting these to an array of tuple would be unusual. What you seemingly have are dictionary's

Example

private class SearchMetadataJson
{
      public string entertain { get; set; }
      public string master { get; set; }
      public string memail { get; set; }
      public string key { get; set; }
      public Dictionary<int,string> mood { get; set; }
      public int? soundnumber { get; set; }
      public int? ftv { get; set; }
      public int? com { get; set; }
      public Dictionary<int,string> sims { get; set; }
      public Dictionary<int,string> keysecond { get; set; }
      public string popt { get; set; }
     // public (string, string) syncs { get; set; }
 }

Its debatable whether the last property is an object or another dictionary as well...

"syncs":{
   "Other pubber":"example2@example.com"
}

However, ill leave that up to you


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...