为了账号安全,请及时绑定邮箱和手机立即绑定

如何将字符串值转换为 json?

如何将字符串值转换为 json?

哆啦的时光机 2022-09-07 18:00:24
我有一个用逗号和“=”分隔的值字符串。我需要将其转换为正确的json格式:value = value.replace("=", ":");String [] arrayStr=value.split(",");JsonObjectBuilder builder = Json.createObjectBuilder();String key = null;for (String s: arrayStr){    if(key == null) {        key = s;    } else {        builder.add(key, s);        key = null;    }}JsonObject val = builder.build();以下是我拥有的内容以及我想如何表达它:[{Locale=en, Address={House=138, Street=Whitefield Road, CityDistrict=Bangalore, City=Bangalore, District=Bangalore, RegionCode=KA, Region=Whitefield, CountryCode=IND, Country=India, PostalCode=560066}}, {Locale=de, Address={House=138, Street=Whitefield Road, CityDistrict=Bangalore, City=Bangalore, District=Bangalore, RegionCode=KA, Region=Whitefield, CountryCode=IND, Country=India, PostalCode=560066}}][{"Locale":"en","Address":{"House":"138","Street":"Whitefield Road","CityDistrict":"Bangalore","City":"Bangalore","District":"Bangalore","RegionCode":"KA","Region":"Whitefield","CountryCode":"IND","Country":"India","PostalCode":"560066"}},{"Locale":"de","Address":{"House":"138","Street":"Whitefield Road","CityDistrict":"Bangalore","City":"Bangalore","District":"Bangalore","RegionCode":"KA","Region":"Whitefield","CountryCode":"IND","Country":"India","PostalCode":"560066"}}]
查看完整描述

1 回答

?
牛魔王的故事

TA贡献1830条经验 获得超3个赞

String value = arrayObject.get(VALUE).toString(); 
JSONArray array = new JSONArray(value);


查看完整回答
反对 回复 2022-09-07
  • 1 回答
  • 0 关注
  • 113 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信