Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.FormatException of a string [duplicate]

I'm getting System.FormatException: Input string was not in a correct format when running this method.

The values of the fields:

arrayName = "requester";
fieldList = "\"name\" : \"shimshon\""; // "name" : "shimshon"


public override string ToString()
{
   var val = string.Format("\"{0}\" : { {1} }", arrayName, fieldList);

   return val;
}

the expect result of the method is

"requester" : { "name" : "shimshon" }

What is wrong with this format?

like image 962
shimshon Avatar asked Feb 03 '26 01:02

shimshon


2 Answers

I think you want:

var val = string.Format("\"{0}\" : {{ {1} }}", arrayName, fieldList);

Note the doubled {{ and }} which is the escape sequence necessary to get braces literally into the output.

like image 182
DonBoitnott Avatar answered Feb 05 '26 15:02

DonBoitnott


Try

var val = string.Format("\"{0}\" : {{ {1} }}", arrayName, fieldList);
like image 21
Arsen Mkrtchyan Avatar answered Feb 05 '26 13:02

Arsen Mkrtchyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!