0

I have a question. i know i can pass a jsonstring via ajax request to the server as string but can i convert the passed jsonstring to byte[] array on the server side? can you show me codes on how to do it? i tried this one.

System.Text.Encoding.ASCII.GetBytes(inputstring);
2
  • what language is that on the server side? C# ? the json is just a string... you can do with it whatever you wish or whatever the language knows on the servers side Commented Mar 12, 2012 at 8:40
  • yes c#. but with the {} and '' will it still work? can you give me a sample code on how can i convert a json string to byte[] array? Commented Mar 13, 2012 at 0:46

1 Answer 1

2

Here's a sample code that converts a JSON-string to a byte-array:

public static byte[] JsonStringToByteArray(string jsonString)
{
    var encoding = new UTF8Encoding();
    return encoding.GetBytes(jsonString.Substring(1, jsonString.Length - 2));
}

Hope this helps!

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

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.