✅ Map json to a dto issue
I want to map my json to a dto
this is my json!
public WixNameDto()
{
this.First = string.Empty;
this.Last = string.Empty;
}
[JsonPropertyName("first")]
public string First;
[JsonPropertyName("last")]
public string Last;
}
}
´´´
I used system.text.json
10 Replies
The first problem, as @0x686f676779303737 mentioned, is that those are fields, not properties
How exactly are you calling System.Text.Json? Are you calling
JsonSerializer.Deserialize<WixNameDto>(json)
?-# summoned
i declared it as properties but still dont work
yes this way
thats the other thing Canton wanted to point out
Right, so look at your JSON. In the outermost object, it's expecting a key "contact"
(And then inside that it's expecting "name", and only inside that is it expecting "first" and "last")
So you need to deserialize into an object which has a property "contact"
okay i think it worked with properties
thx really much!
:kekw:
I don't see how it could possibly work without creating those extra objects, but ok!
!close
Closed!
actually i had an object called contactdto and within there was namedto
but it was too big to handle
so i posted this
That's why I asked the question "Are you calling
JsonSerializer.Deserialize<WixNameDto>(json)
?", and you said "yes"
><
Don't say "yes" if the answer is actually "no" in future, please