jsonobject转string
时间: 2023-08-30 09:09:56 浏览: 86
JavaScript中json对象和string对象之间相互转化
使用JsonMapper.ToJson方法可以将JsonObject转换为string。比如在C#中,可以使用以下代码将JsonObject转换为string:
JsonData jsonData = new JsonData();
jsonData["state_code"] = 101;
JsonData objectData = new JsonData();
objectData["goods_name"] = "M1";
objectData["goods_number"] = 2;
objectData["port"] = "";
jsonData["data"] = objectData;
string jsonString = JsonMapper.ToJson(jsonData);
Debug.Log(jsonString);
在Java中,可以使用以下代码将JsonObject转换为string:
JSONObject object = new JSONObject();
object.put("state_code", 101);
JSONObject objectData = new JSONObject();
objectData.put("goods_name", "M1");
objectData.put("goods_number", 2);
objectData.put("port", "");
object.put("data", objectData);
String jsonString = object.toString();
System.out.println(jsonString);
以上代码分别展示了在C#和Java中将JsonObject转换为string的方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Json对象和string之间的转换](https://blog.csdn.net/u012138730/article/details/107379048)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文