android - 如何在 Android 中创建 JSON

标签 android json

如何在 Android 中创建嵌套的 JSON。 JSON 数据应如下所示:

JSON
Customername = Roshan
Customercode = 100
Customercity = Ernakulam
Customerstate = Kerala
Customercountry = India
Customersales
    Productname = Biscuit
    Productcode = 123
    Producttype = Food
Customersales
    Productname = Shoes
    Productcode = 234
    Producttype = Dress

注意:我能够在没有嵌套的情况下创建 JSON,但我无法创建嵌套的 JSON 数据。我们如何做到这一点?

最佳答案

您将使用 JSONObject。

Link

创建一个 JSONObject:

JSONObject json = new JSONObject();

添加元素:

json.accumulate(key,value);

获取 JSON:

json.toString;

关于android - 如何在 Android 中创建 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24261049/

相关文章:

ruby - 在 Chef 中读取文件而不写入节点

android - 使用代理服务器的手机上的OAuth是否太麻烦了?

android - TabLayout ViewPager 图标显示在 Android 的角落

android - 为什么这个 xamarin android 菜单文本没有显示?

android - 如何从系统包中过滤掉应用程序

java - 如何用空值替换\"

Android - 显示进度条时出现 'Cant create handler' 错误

Python:如何从 UDP 接收数据包中获取 JSON 对象

javascript - 在 D3.js (V4) 中创建分类折线图

json - 快速解码嵌套的 JSON