JSONObject转换为Android的String [英] JSONObject to String Android

查看:1950
本文介绍了JSONObject转换为Android的String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有这些括号{ }的情况下将"{hello1: hello2: hey}"之类的JSONObject转换为"hello1: hello2: hey"?

how can I convert a JSONObject like "{hello1: hello2: hey}" to "hello1: hello2: hey" without these brackets { } ?

我知道有机会使用JSONObject.tostring,但随后我将得到一个带有方括号的字符串.

I know that there is a opportunity to use JSONObject.tostring but then I'll get a string with the brackets.

谢谢.

推荐答案

只需执行子字符串或字符串替换.

Just do a substring or string replace.

子字符串示例:

JSONObject a  = new JSONObject("{hello1: hi, hello2: hey}");
String b = a.toString().substring(1, a.toString().length() - 1);

字符串替换示例:

JSONObject a  = new JSONObject("{hello1: hi, hello2: hey}");
String b = a.toString().replace("{", "");
String c = b.toString().replace("}", "");

这篇关于JSONObject转换为Android的String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆