Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array of string into a string ready for JSON formatting

Tags:

json

c#

I have an array of string values obtained from a method and I want to convert this array into a HTML readable format for getting/posting (eg. value=[12,21])

I have tried the following:

string[] array1 = methodToGetStringArray(); //assuming [12,21] for example
string finalString = "value="+array1; //intended output is value=[12,21]

Which of course doesn't work.

I would like to know the method to provided the value as shown above.

like image 572
aeee98 Avatar asked Apr 26 '26 13:04

aeee98


1 Answers

You can try,

string finalString = String.Format("value=[{0}]", string.Join(", ", array1));

finalString should return,

value=[12, 21]
like image 121
choz Avatar answered Apr 29 '26 01:04

choz



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!