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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:18:38+00:00 2026-06-09T20:18:38+00:00

I want to implement a framework to map JSON string to the calling of

  • 0

I want to implement a framework to map JSON string to the calling of C# method. For example, I have a C# class Calculator defined as below.

// C# class
class Calculator
{
public:
    int add (int x, int y);
    int sub (int x, int y);
}

There is a JSON string as below. When the framework receives this string, it creates/new an object of class Calculator. Then call its function add. And pass the value 12 and 43 to the function as parameters.

// JSON string
"{
\"class\":\"Calculator\",
\"method\":\"add\",
\"parameters\": {
    \"x\" : \"12\", \"y\" : \"43\"
    }
}"

Is there any 3rd party library to implement this? Or how can I implement it by myself?

  • 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-09T20:18:39+00:00Added an answer on June 9, 2026 at 8:18 pm

    A small working sample. Of course many checks are missing. (Using Json.Net)

    string jsonstring = "{\"class\":\"Calculator\",\"method\":\"add\",\"parameters\": { \"x\" : \"12\", \"y\" : \"43\" }}";
    
    var json = (JObject)JsonConvert.DeserializeObject(jsonstring);
    
    Type type = Assembly.GetExecutingAssembly()
                        .GetTypes()
                        .First(t => t.Name==(string)json["class"]);
    
    object inst = Activator.CreateInstance(type);
    var method =  type.GetMethod((string)json["method"]);
    var parameters = method.GetParameters()
            .Select(p => Convert.ChangeType((string)json["parameters"][p.Name], p.ParameterType))
            .ToArray();
    var result =  method.Invoke(inst, parameters);
    
    var toReturn = JsonConvert.SerializeObject(new {status="OK",result=result });
    

    –

    class Calculator
    {
        public int add(int x, int y)
        {
            return x + y;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a j2ee web application running on Spring framework. I want to implement
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
i starter in jqgrid, i want implement inline edit in jqgrid i have this
I am still learning .NET framework and I want to implement multi-tier application just
I am using zend framework on windows. I want to implement ajax in my
I have a question similar to This one . But I want to implement
hi there i am woring with java play framework and i want to implement
So I have two custom complex types like this (oversimplified for this example): public
When i want to implement SQLite in a WPF-Application (.Net Framework 4), the programm
I am creating one web application in GRAILS framework.In that I want to implement

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.