9

I am trying to format a Json input to a JSON RPC. For example, the JSON am goint to post is as following,

"{"filter":{ "Ids": [123, 124], "Types":["EMPLOYEE"]}}"

which I expect to return users with id 123, 124 and of type EMPLOYEE. But for the Ids parameter, I want to may it dynamic so that I can set the value in my C# calling method like the following

string.Format("{\"filter\":{ \"Ids\": [{0}], \"Types\":[\"EMPLOYEE\"]}}", "123, 124");

when doing so, I get the format exception "Input string was not in correct format"....

I know, I can build up the string using string.concat or string builder. Am just curious, if there is any solution to overcome this string.format exception in the event when a string has curly brackets (am assuming this is the cause of the exception) already.

1
  • 2
    { needs to be escaped if you want to use it literally. Commented Apr 19, 2013 at 9:11

1 Answer 1

21

You have to escape "{" and "}"-chars by using "{{" resp. "}}".

See "Escaping Braces" in http://msdn.microsoft.com/en-us/library/txafckwd.aspx.

Sign up to request clarification or add additional context in comments.

Comments

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.