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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:47:30+00:00 2026-06-15T10:47:30+00:00

I would like to deserialize a JSON-RPC request in two steps: Step 1: Parse

  • 0

I would like to deserialize a JSON-RPC request in two steps:

Step 1: Parse id and method into a base class
Step 2: Parse params into a second class depending on method

Example:

interface IAction
{
    bool Exec();
}

class Request
{
    [JsonProperty("method")]
    public string Method;

    [JsonProperty("params")]
    public RawJson Params;

    [JsonProperty("id")]
    public RawJson Id;
}

class Whisper : IAction
{
    [JsonProperty("to")]
    public string To;

    [JsonProperty("msg")]
    public string Message;

    public bool Exec()
    {
        // Perform the whisper action
        return true;
    }
}

class Say : IAction
{
    [JsonProperty("msg")]
    public string Message;

    public bool Exec()
    {
        // Perform the say action
        return true;
    }

}

Code (if there were such an object as RawJson)

Request req = JsonConvert.DeserializeObject<Request>(s);
if( req.Method == "whisper" )
{
    Whisper whisper = RawJson.DeserializeObject<Whisper>();
    whisper.Exec();
}

One way to solve it would be if Json.NET has some kind of raw json object, but I can’t find one.

So, have I just missed the raw object or is there another good way to do this?


Ps. The id value can be anything: null, string, int, array, etc. It should just be returned in the json-rpc response.

  • 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-15T10:47:32+00:00Added an answer on June 15, 2026 at 10:47 am

    You can use dynamic

    dynamic dynJson = JsonConvert.DeserializeObject(s)
    if(dynJson.method=="whisper")
    {
        var to = dynJson.@params.to; //since params is reserved word
    }
    

    This is also possible

    string json = "{method:'whisper',params:{to:'aaa',msg:'msg1'}}";
    
    var jObj = JsonConvert.DeserializeObject(json) as JObject;
    if (jObj["method"].ToString() == "whisper")
    {
        var whisper = JsonConvert.DeserializeObject<Whisper>(jObj["params"].ToString());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to deserialize the following json using DataContractJsonSerializer: coordinates: [ [ 18.008966033966707,
I will start off by showing the JSON I would like to deserialize: {FleetsCollection:[{FleetId:2,Nickname:2007
I am a beginner in Monotouch. I would like to deserialize Json data using
In my windows mobile application i would like to deserialize and serialize JSON objects.
I would like to use this kind of Objects with json: class Message{ int
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Would like to make anapplication in Java that will not automatically parse parameters used
I'm working with the DataContractJsonSerializer in Silverlight 4 and would like to deserialize the
I have some models in a Play! application that I would like to serialize/deserialize
I would like to serialize and deserialize objects without having to worry about the

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.