1

I have created a REST web service that should get a JSON string and convert it to an object in C#. I have created my classes and used the deserialization:

RootObject test = JsonConvert.DeserializeObject<RootObject>("id"); 

So far so good, I need to call my function :

public string JSONData(string id) 

Is there a way to insert my JSON in the URL so I can trigger my function, or am I missing something fundamental?

http://localhost/RestSrv/Json/....

What should I put in the ... that will give value to my id string and call my JSONData function that will deserialize the JSON after? Should I use an online JSON convert to URL tool?

Paul Roub
  • 35,100
  • 27
  • 72
  • 83
Aereal
  • 103
  • 7
  • Please read this: http://stackoverflow.com/questions/14551194/how-are-parameters-sent-in-an-http-post-request, it explains how to include params in both a GET and POST request – Sid Jul 24 '14 at 21:47

1 Answers1

0

I can think of two ways to do this

  1. Send JSON via HTTP POST with Content-Type: application/json header

  2. Send HTTP Query String with the required data. For example

    ?object[type]=person&children_names[]=Mia&children_names[]=Anna

Would convert to JSON (https://www.convertonline.io/convert/query-string-to-json)

{"object":{"type":"person"},"children_names":["Mia","Anna"]}

Option 1 is better since URL string can be long and have a length limitation.

faboulaws
  • 1,259
  • 11
  • 15