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.
You have to escape "{" and "}"-chars by using "{{" resp. "}}".
See "Escaping Braces" in http://msdn.microsoft.com/en-us/library/txafckwd.aspx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With