string.Format对于带有大括号的字符串,输入字符串格式不正确已作为格式C#的一部分

Ant*_*dha 8 c# json

我正在尝试将Json输入格式化为a JSON RPC.例如,JSON发布的帖子如下,

"{"filter":{ "Ids": [123, 124], "Types":["EMPLOYEE"]}}"
Run Code Online (Sandbox Code Playgroud)

我期望返回ID为123,124且类型为EMPLOYEE的用户.但对于Ids参数,我想它可能是动态的,以便我可以在我的C#调用方法中设置值,如下所示

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

这样做,我得到格式异常"Input string was not in correct format"....

我知道,我可以使用string.concat或建立字符串string builder.我只是好奇,如果有一个解决方案来克服这个string.format异常,当一个字符串已经curly brackets(假设这是异常的原因)已经.

ulr*_*chb 20

你必须通过使用"{{"resp来逃避"{"和"}" - 字符."}}".

请参阅http://msdn.microsoft.com/en-us/library/txafckwd.aspx中的 "转义大括号" .