我想传递name:searitem作为参数: byte [] byteData = Encoding.UTF8.GetBytes(); 我尝试过的事情: 这就是我所做的但没有一个工作: 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};
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" };
推荐答案byte[] byteData = Encoding.UTF8.GetBytes("{ "name": "searitem" }");
这不起作用,因为你没有正确处理字符串中的引号; name 的报价实际上导致字符串关闭。 如果你想在字符串中加引号,你必须逃避,输入 \:
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 \":
byte[] byteData = Encoding.UTF8.GetBytes("{ \"name\": \"searitem\" }");
更多推荐
如何将json参数传递给字节对象
发布评论