如何将json参数传递给字节对象

编程入门 行业动态 更新时间:2024-10-15 16:17:42
本文介绍了如何将json参数传递给字节对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想传递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参数传递给字节对象

本文发布于:2023-11-25 20:46:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字节   如何将   对象   参数   json

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!