Click here to Skip to main content
15,917,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to pass "name": "searitem" as a parameter to:
byte[] byteData = Encoding.UTF8.GetBytes();

What I have tried:

This is what I have done but none is working:
byte[] byteData = Encoding.UTF8.GetBytes("{ "name": "searitem" }");
//byte[] byteData = Encoding.UTF8.GetBytes({"name": "searitem" });
//byte[] byteData = Encoding.UTF8.GetBytes("name": "searitem");
//byte[] byteData = Encoding.UTF8.GetBytes{ "name": "searitem" };
Posted
Updated 2-May-18 7:10am

1 solution

C#
byte[] byteData = Encoding.UTF8.GetBytes("{ "name": "searitem" }");
This isn't working because you did not properly handle the quotes inside the string; the quote at "name is actually causing the string to close.

If you want to put quotes in strings, you have to escape them, by typing \":
C#
byte[] byteData = Encoding.UTF8.GetBytes("{ \"name\": \"searitem\" }");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900