Android: 生成带动态 key 的 JSON

  在某个商品评价接口中,后台要求点击评论后返回以上数据:

{
    "order": {                                // key 固定为 order, 表示整个订单的信息
        "order_id": "2017071900000000",       // 订单号
        "deliverycredit": "5",                // 发货速度评分 (1-5)
        "servicecredit": "5",                 // 服务态度评分 (1-5)
        "desccredit": "5"                     // 描述相符评分 (1-5)
    },
    "goods_id1": {                            // 商品 id
        "scores": "5",                        // 商品评分 (1-5)
        "result": "3",                        // 好中差评
        "content": "非常好",                   // 评价内容
        "isanonymous": "1",                   // 匿名
        "image": [                            // 买家返图
            "http://konoha.com/image1.jpg",
            "http://konoha.com/image2.jpg"
        ]
    },
    "goods_id2": {                            // 和上面一样
        "scores": "1",
        "result": "1",
        "content": "糟透了",
        "isanonymous": "0",
        "image": [
            "http://konoha.com/image3.jpg",
            "http://konoha.com/image4.jpg"
        ]
    }
}

  这里有个麻烦的地方,就是单个商品评价的 Object Key 不是固定的,跟随 goods_id 变化。不过也不碍事,特殊情况特殊处理就是了。

[……]

继续阅读