Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9265507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:05:06+00:00 2026-06-18T14:05:06+00:00

I have a problem deserializing this JSON response { posts: { Pippo: { text:

  • 0

I have a problem deserializing this JSON response

{
  "posts": {
    "Pippo": {
      "text": "text1",
      "link": "link1"
    },
    "Pluto": {
      "text": "text2",
      "link": "link2"
    }
  }
}

I’m using this model

public class postModel
{
    public string text { get; set; }
    public string link { get; set; }
}

public class postFields
{
    public postModel post { get; set; }
}

public class RootObject
{
    public Dictionary<string, postFields> posts { get; set; }
}

then I deserialize this way

var deserialized = JsonConvert.DeserializeObject<RootObject>(json);

then I stop. I cannot read values because I try this

foreach (var value in deserialized)
            {
                new postModel
                {
                    text = value.Value.post.text,
                    link = value.Value.post.link
                };
            }

Then I get NullReferenceException, because the name of JSON property isn’t “post” but Pippo, Pluto, etc.

Can someone help me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T14:05:07+00:00Added an answer on June 18, 2026 at 2:05 pm

    Thanks to both of you; I solved this way:

    var main = JObject.Parse(json);
    
            foreach (var mainRoute in main.Properties()) // this is "posts"
            {
                foreach (var subRoute in mainRoute.Values<JObject>().SelectMany(x => x.Properties())) // this is "Pippo", "Pluto"
                {
                    var deserialized = JsonConvert.DeserializeObject<postModel>(subRoute.Value.ToString());
    
                    new postModel
                    {
                        text = deserialized.text,
                        link = deserialized.link
                    };
                }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with deserializing this JSON data due to duplicate property name
I have a problem with deserializing JSON data from an external REST service. Depending
I have a problem deserializing a JSON string using Jackson (but I have no
I have a JSON response like this { car:100, house:200, bike:300 } But sometimes
I have problem with my query on C, I’m using the oci8 driver. This
Hey, I am having a problem deserializing base64 json back into the .net object
I have a problem deserializing some XML; the XML supplied by a third party
We have a problem with deserializing an exception. I am fully aware that it's
I have to deserialize JSON strings that I don't have any control over. This
I'm using the jackson library for serializing/deserializing to/from JSON. I need that this JSON

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.