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 7742515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:17:43+00:00 2026-06-01T09:17:43+00:00

I am trying to parse some JSON on the Windows Phone with DataContractJsonSerializer .

  • 0

I am trying to parse some JSON on the Windows Phone with DataContractJsonSerializer. All of the JSON responses have the same format: status, message, data. The status and message field always have the same type, but the data field contains a call-specific object. Here are some examples:

Hash

{
status: 0,
message: "No error",
data:
  {
    team: "test",
    startTime: "1969-12-31 19:00:00 -0500",
    endTime: "2000-01-01 00:00:00 -0500",
    max_photos: 30,
    max_judged_photos: 24
  }
}

List

{
status: 0,
message: "No error",
data:
  [
    {
      id: 1,
      game_id: "Test",
      description: "Test",
      points: 100
    },
    {
      id: 2,
      game_id: "Test",
      description: "Test",
      points: 1000
    }
  ]
}

I would like to parse the responses into a generic Response object containing status, message, and data. I want to then further parse the JSON in data into the correct object (hash or list). Here is what my Response class currently looks like:

[DataContract]
public class Response
{
    [DataMember(Name = "status", IsRequired=true)]
    public STATUS Status { get; set; }

    [DataMember(Name = "message", IsRequired = true)]
    public string Message { get; set; }

    [DataMember(Name = "data", IsRequired = true)]
    public ?????? Data { get; set; }
}

My question is, is there a generic JSON container I can use to hold the inner JSON in the data field (so that I can parse that seperately) or is there a better way of solving this altogether? I’d rather not have separate Response classes for each response type.

Thank you.

  • 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-01T09:17:44+00:00Added an answer on June 1, 2026 at 9:17 am

    Since data is sometimes an array and sometimes a single object, you can not deserialize it to a type safe class.

    But you can use Json.Net (which works on WP7) to parse the json string.

    JObject json = (JObject)JsonConvert.DeserializeObject(jsonstr);
    if (json["data"] is JArray)
    {
        foreach(var item in json["data"])
            Console.WriteLine(item["id"]);
    }else{
        Console.WriteLine(json["data"]["startTime"]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some JSON code in a string that I am trying to parse.
I'm trying to parse some JSON that is sent to me and it's all
I'm trying to parse some JSON data from the Google AJAX Search API. I
I'm trying to parse some JSON in Grails using the grails.converters.JSON library. I have
I am trying to parse all the data that I have populated in my
I'm trying to parse some huge JSON file (like http://eu.battle.net/auction-data/258993a3c6b974ef3e6f22ea6f822720/auctions.json ) using gson library
So I'm trying to parse some nested json and the way I'm trying to
I am trying to parse some XML i have retrieved via e4x in an
I'm trying to parse some data returned by a 3rd party app (a TSV
I am trying to parse some JSON. I've passed a constant key value and

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.