© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
8 replies
Dasic

Newtonsoft.Json deserialize issue [Answered]

I have a json string. For example this one:
{"type":"accept","id":0,"ms_id":"00000","user_id":"000000000000","item_name":"Test Item","acc_name":"account"}
{"type":"accept","id":0,"ms_id":"00000","user_id":"000000000000","item_name":"Test Item","acc_name":"account"}

How can I deserialize some fields to a structure field in my class? For instance:
public class Order
{
    [JsonProperty("id")] public int Id { get; init; }
    [JsonProperty("item_name")] public string ItemName { get; init; }

    [JsonProperty("ms_id")] public long MessageId { get; init; }

    public Account Account { get; init; }
}

public struct Account
{
    [JsonProperty("user_id")] public long UserId { get; init; }
    [JsonProperty("acc_name")] public long Nickname { get; init; }
}
public class Order
{
    [JsonProperty("id")] public int Id { get; init; }
    [JsonProperty("item_name")] public string ItemName { get; init; }

    [JsonProperty("ms_id")] public long MessageId { get; init; }

    public Account Account { get; init; }
}

public struct Account
{
    [JsonProperty("user_id")] public long UserId { get; init; }
    [JsonProperty("acc_name")] public long Nickname { get; init; }
}

How can I deserialize the string to put these two fields in an
Account
Account
field?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Newtonsoft.Json issue
C#CC# / help
17mo ago
How to deserialize dictionary using Newtonsoft [Answered]
C#CC# / help
4y ago
Deserialize JSON to dynamic object without Newtonsoft.Json
C#CC# / help
4y ago
Best way to deserialize duplicate JSON API responses (Using Newtonsoft.JSON)
C#CC# / help
16mo ago