LoginSignup
0
1

More than 1 year has passed since last update.

json デシリアライズ

Posted at

jsonのデシリアライズで苦戦した。
JsonSerializerでやってみたのだけど。
javascriptでjsonにして送って、C#でデシリアライズを試みるも

        var person2 = JsonSerializer.Deserialize<Person>(json, options);
        Console.WriteLine($"{person2?.tel} {person2?.name} {person2?.address} {person2?.Email}");

Consoleに辿り着かずに処理が終了してしまう。

原因は型だった。
.telをintで定義していたのだけど、送る側はstringだった。

あと、なぜか先頭のプロパティだけnullになってしまって。

    [JsonPropertyName("Name")]
    public string? name { get; set; }
    public string? tel { get; set; }

[JsonPropertyName("Name")]、これの意味が理解できていなかったのが原因。

参考にしたサイト
https://hirahira.blog/json-serialization/

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1