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

  • SEARCH
  • Home
  • 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 7033365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:03:26+00:00 2026-05-28T01:03:26+00:00

I’m trying to deserialize some JSON data into objects for an application. Up until

  • 0

I’m trying to deserialize some JSON data into objects for an application. Up until now it’s been fine because the properties on the JSON data was static (key with a value). Now I’ve got a result where the key is a dynamic piece of data.

Here’s an example JSON url:

http://en.wikipedia.org/w/api.php?action=query&format=json&pageids=6695&prop=info

The resulting JSON for this is:

{ "query" : { "pages" : { "6695" : { "counter" : "",
          "lastrevid" : 468683764,
          "length" : 8899,
          "ns" : 0,
          "pageid" : 6695,
          "title" : "Citadel",
          "touched" : "2012-01-03T19:16:16Z"
        } } } }

Okay, that’s great except I can’t deserialize the “pages” data into an object. If I were to define a class for the pages it would have to look like this:

public class 6695
{
    public string counter { get; set; }
    public int lastrevid { get; set; }
    public int length { get; set; }
    public int ns { get; set; }
    public int pageid { get; set; }
    public string title { get; set; }
    public string touched { get; set; }
}

In order to deserialze the contents (using JsonConvert.Deserialize(jsondata)) and we all know we can’t have a class called 6695. Not only that, the name of the class would have to be different (for example pageid=7145 would have to be the 7145 class).

I can seem to pluck some values out if I use something like JObject.Parse(content) and then access items as JArrays but it’s pretty ugly and I’m still stuck on trying to get out the data from the pages array.

Looking for someone to help with this. I don’t think it’s uncommon, it’s just not JSON data I’ve come across before and not sure how to handle it.

Thanks!

PS forgot to mention this is on Windows Phone 7 so “dynamic” isn’t available!

  • 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-05-28T01:03:26+00:00Added an answer on May 28, 2026 at 1:03 am

    Here is how you do using https://github.com/facebook-csharp-sdk/simple-json ( https://nuget.org/packages/SimpleJson ).

    var text = "{\"query\":{\"pages\":{\"6695\":{\"pageid\":6695,\"ns\":0,\"title\":\"Citadel\",\"touched\":\"2012-01-03T19:16:16Z\",\"lastrevid\":468683764,\"counter\":\"\",\"length\":8899}}}}";
    

    (Using dynamic)

    dynamic json = SimpleJson.DeserializeObject(text);
    string title = json.query.pages["6695"].title;
    
    foreach (KeyValuePair<string, dynamic> page in json.query.pages)
    {
        var id = page.Key;
        var pageId = page.Value.pageid;
        var ns = page.Value.ns;
    }
    

    (Using strongly typed classes)

    class result
    {
        public query query { get; set; }
    }
    class query
    {
        public IDictionary<string, page> pages { get; set; }
    }
    class page
    {
        public long pageid { get; set; }
        public string title { get; set; }
    }
    
    var result = SimpleJson.DeserializeObject<result>(text);
    

    [Update]

    on windows phone where dynamic is not supported and you don’t want to use strongly typed classes.

    var json = (IDictionary<string, object>)SimpleJson.DeserializeObject(text);
    var query = (IDictionary<string, object>)json["query"];
    var pages = (IDictionary<string, object>)query["pages"];
    var pageKeys = pages.Keys;
    var page = (IDictionary<string, object>)pages["6695"];
    var title = (string)page["title"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

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.