0

I would like to get a json file in my c# code. But to get this file I need to add some parameters:

{
 id = 1;
 jsonrpc = "2.0";
 method = getPosts;
 params =     {
    page = 0;
 };
}

How can I get the above parameters in the following code to recieve the Json file.

        public void LoadData()
    {
        WebRequest.RegisterPrefix("http://example.com", WebRequestCreator.ClientHttp);
        Uri serviceUri = new Uri("http://example.com/jsonrpc.php");
        WebClient downloader = new WebClient();
        downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
        downloader.OpenReadAsync(serviceUri);

    }
Patrick Jore
  • 43
  • 1
  • 7

1 Answers1

0

create your JSON with JavaScriptSerializer class,here with some example Turn C# object into a JSON string in .NET 4 ,then send data with POST request

extract responsed json with [Deserialize]msdn.microsoft.com/en-us/library/bb355316.aspx,before that you need declared a type matched class,or deserializing with [Dynamic Object]stackoverflow.com/questions/3142495/deserialize-json-into-c-sharp-dynamic-object

Community
  • 1
  • 1
Rick
  • 11
  • 2