1

I made a control

and I generated a string with javascript from a javascript array using

Sys.Serialization.JavaScriptSerializer.serialize(array);

this is the string generated

"["name", "Code", "Alias"]"

this string is send to my control with a postback.

Now I need to know the best way to make an array from this string using C#

2
  • you're trying way too hard man. What web technology are you using to get from the javascript back to the c#? If it's something like WebAPI or mvc then there is just standard model binding. I wasn't the down-voter, but you got downvoted because the question is somewhat half-baked. Commented Sep 9, 2014 at 13:35
  • I'm creating an advanced text input control using the scriptcontrol in C#. I have a lot of data in my javascript but I need some data set back when postback occures. thats why I added this string into a hiddenfield which postback capture and my textcontrol get its new changed settings after postback. Commented Sep 9, 2014 at 13:38

2 Answers 2

3

You can use JavaScriptSerializer class:

var serializer = new JavaScriptSerializer();
var array = serializer.Deserialize<string[]>(yourString);

Note: You need to add a reference to System.Web.Extensions.dll

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

1 Comment

this is exactly what I was looking for. I already knew about the split but I thought there was some sort of already built in function for it. Thx a lot man
0
String[] splitByComma = yourString.Split(',');
foreach(String splitString in splitByComma)
{
    splitString.Replace("\"","").Replace("[","").Replace("]","");
}

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.