1

I am not trying to post just JSON, but instead I want to post a JSON array to just one parameters of the post request.

Code:

        var locations = new Dictionary<string, object>();
        locations.Add("A", 1);
        locations.Add("B", 2);
        locations.Add("C", 3);

        request.AddObject(locations);
        request.AddParameter("date", 1434986731000);

AddObject fails, because I think the new RestSharp JSON serializer can't handle dictionaries. (error here: http://pastebin.com/PC8KurrW)

I tried also just request.AddParameter("locations", locations); but that doesnt serialize to json at all.

I want the request to look like

locations=[{A:1, B:2, C:3}]&date=1434986731000

the [] is important to have, even its only 1 JSON object. It's an array of JSON objects.

1 Answer 1

5

Not very slick, but this would work:

var request = new RestSharp.RestRequest();

var locations = new Dictionary<string, object>();
locations.Add("A", 1);
locations.Add("B", 2);
locations.Add("C", 3);

JsonObject o = new JsonObject();

foreach (var kvp in locations)
{
    o.Add(kvp);
}

JsonArray arr = new JsonArray();
arr.Add(o);

request.AddParameter("locations", arr.ToString());
request.AddParameter("date", 1434986731000);
Sign up to request clarification or add additional context in comments.

1 Comment

This works. I will wait to see if any other "slick" options appear, but noted you were the first and this works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.