Tim280 2022-04-11 23:12 采纳率: 20%
浏览 42
已结题

java 如何取得對應值 JSON

#以下是我的JSON
{
"121874": {
"sku": 121874,
"reference": "002331",
"reference2": "002331",
"description": "USB-C - Lightning Cable",
"warehouse_id": 1,
"weight": 70,
"dimensions": {
"length": 92,
"width": 87,
"height": 20
},
"items_in_box": 1,
"level": "40",
"atp": "40",
"master_level": "40",
"master_atp": "40",
"status": 1,
"status_string": "on",
"lot_number": "",
"tht_alert": "none",
"tht_date": false,
"tht_minimum": false,
"last_update": {
"date": "2022-04-04 08:54:41",
"timezone_type": 3,
"timezone": "Europe/Brussels"
},
"last_atp_update": {
"date": "2022-04-04 08:54:41",
"timezone_type": 3,
"timezone": "Europe/Brussels"
}
},
"121995": {
"sku": 121995,
"reference": "002234SL",
"reference2": "002234SL",
"description": "AirPods 3 (Silver)",
"warehouse_id": 1,
"weight": 0,
"dimensions": {
"length": 0,
"width": 0,
"height": 0
},
"items_in_box": 1,
"level": 0,
"atp": 0,
"master_level": 0,
"master_atp": 0,
"status": 1,
"status_string": "on",
"lot_number": "",
"tht_alert": "none",
"tht_date": false,
"tht_minimum": false,
"last_update": {
"date": "2022-04-01 03:26:59",
"timezone_type": 3,
"timezone": "Europe/Brussels"
},
"last_atp_update": {
"date": "2022-04-01 03:26:59",
"timezone_type": 3,
"timezone": "Europe/Brussels"}

#我有reference 這個數據. 想對應 sku 。 謝謝你們幫助!

  • 写回答

5条回答 默认 最新

  • 关注

    你题目的解答代码如下:

    obj={ "121874": { "sku": 121874, "reference": "002331", "reference2": "002331", "description": "USB-C - Lightning Cable", "warehouse_id": 1, "weight": 70, "dimensions": { "length": 92, "width": 87, "height": 20 }, "items_in_box": 1, "level": "40", "atp":
    "40", "master_level": "40", "master_atp": "40", "status": 1, "status_string": "on", "lot_number": "", "tht_alert": "none", "tht_date": false, "tht_minimum": false, "last_update": { "date": "2022-04-04 08:54:41", "timezone_type": 3, "timezone": "Europe/Brussels"
    }, "last_atp_update": { "date": "2022-04-04 08:54:41", "timezone_type": 3, "timezone": "Europe/Brussels" } }, "121995": { "sku": 121995, "reference": "002234SL", "reference2": "002234SL", "description": "AirPods 3 (Silver)", "warehouse_id": 1, "weight":
    0, "dimensions": { "length": 0, "width": 0, "height": 0 }, "items_in_box": 1, "level": 0, "atp": 0, "master_level": 0, "master_atp": 0, "status": 1, "status_string": "on", "lot_number": "", "tht_alert": "none", "tht_date": false, "tht_minimum": false,
    "last_update": { "date": "2022-04-01 03:26:59", "timezone_type": 3, "timezone": "Europe/Brussels" }, "last_atp_update": { "date": "2022-04-01 03:26:59", "timezone_type": 3, "timezone": "Europe/Brussels"}
    reference = "002234SL";
    sku = "";
    for (n in obj) {
        if (obj[n].reference==reference){
            sku = obj[n].sku;
            break;
        }
    }
    

    如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

问题事件

  • 系统已结题 4月19日
  • 已采纳回答 4月11日
  • 创建了问题 4月11日

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加