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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:47:51+00:00 2026-05-20T05:47:51+00:00

My other question seems to be too generic, so I tought I’d create a

  • 0

My other question seems to be too generic, so I tought I’d create a new one on the details. Sorry if that is considered bad practice.

I am trying to serialize C# objects to JSON strings with MonoTouch and the System.Json namespace in a way that doesn’t require me to descend through the object(s) myself. Is that possible? If yes, how to do it properly?

De-serialization works well by implicitly casting a JsonValue to a string, int, whatever. Also, descending in the hierarchy is no problem. Like so:

JsonValue json = JsonValue.Parse(jsonString);
int mainValue = json["mainValue"];

JsonValue subValues = json["subValues"];
int subValue1 = subValues["subValue1"];

The opposite is only possible with elemental types (string/int/…). Other objects cannot be cast to JsonValue/JsonObject unfortunately. Not even really simple structs with just two ints.

// This works
JsonValue json = new JsonObject(new KeyValuePair<string,JsonValue>("mainValue", 12345));

// Cannot (implicitly) convert type 'MyObjectType' to 'System.Json.JsonValue'
MyObjectType myObject = new MyObjectType();
JsonValue subValues = myObject;

// Cannot (implicitly) convert type 'MySimpleStruct' to 'System.Json.JsonObject'
MySimpleStruct myStruct;
myStruct.x = 1;
myStruct.y = 2;
JsonValue myStructJson = myStruct;

As my object has several levels of other objects nested within, walking through it by myself and assigning all the values would be a great PITA. Is there a simpler way with System.Json?

  • 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-20T05:47:51+00:00Added an answer on May 20, 2026 at 5:47 am

    System.Json doesn’t support arbitrary serialization like this.

    You can use a third party Json library like Newtonsoft, or wait for MonoTouch v4 which will have the DataContractJsonSerializer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From another stackoverflow question, it seems that Android handles large bitmaps differently than other
This relates to my other question on accessing a REST service that uses forms
This is a question for the generic collection gurus. I'm shocked to find that
I feel noob asking this question but it seems that I cant find the
I have a question that I think should not be too complex. I have
Since my other bug got solved, I'm posting a new question for this bug.
I am a C++ beginner, so sorry if the question is too basic. I
For a SO question i quite recently wrote a generic extension method that should
My question is similar to this one , but is different enough that I
I'm pretty sure that this question already has been answered somewhere. It just seems

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.