在 node/javascript 中解析 JSON

编程入门 行业动态 更新时间:2024-10-04 23:32:25

在 <a href=https://www.elefans.com/category/jswz/34/1771450.html style=node/javascript 中解析 JSON"/>

在 node/javascript 中解析 JSON

谁能帮我解析一个 json 我想通读这个 json

"GB": {
        "0005000010105A00": {
            "title_id": "0005000010105A00",
            "eshop_id": "20010000000023",
            "product_code": "WUP-N-HNNA",
            "name": "Netflix",
            "platform": 124,
            "platform_device": "WUP",
            "publisher": 584,
            "banner_url": ".jpg",
            "icon_url": ".jpg",
            "data_size": "63963276",
            "description": "Instantly watch movies and TV episodes streaming from Netflix right to your TV via your Wii U console. Watch as often as you want, anytime you want. Download and install Netflix to get started. New Netflix members can start their one-month free trial today. Cancel anytime. Netflix membership required. Service only available in certain countries. Visit netflix for details. Subscription required.",
            "availability": {
                "eshop": true,
                "retail": false,
                "dates": {
                    "eshop": "2012-11-29",
                    "retail": null
                }
            },
            "screenshots": [
                ".jpg",
                ".jpg",
                ".jpg"
            ],
            "movies": []
        },

只需拿到身份证 无论如何要查找名称并取回 ID? (id是0005000010105A00) 谢谢!

回答如下:

我将做一些假设来帮助你。

首先,我猜你有这样一个对象:

{
  "GB": {
    ...
  }
}

“GB”对象中的每个条目都是具有您描述的形式的对象。

如果是这样,这就是我将如何选择您提供的对象并返回它的“id”(在 JavaScript 社区中通常称为“键”)。

// Get your json data from somewhere like a file or URL and parse it into an object.
let myObject = JSON.parse(myJsonData);

// Create our id variable.  If we don't find the desired name, id will be undefined.
function getId (name) {
  let id;
  Object.entries(myObject.GB).forEach(([key,obj]) => {
    if (obj.name === name) {
      id = key;
    }
  });
  return id;
}

// now netflixId will be the desired id, or undefined if there's no such name found.
let netflixId = getId('Netflix');

希望对您有所帮助。

为了将来参考,你会更好地发布你已经尝试过的东西。

更多推荐

在 node/javascript 中解析 JSON

本文发布于:2024-05-31 00:15:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1771078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:node   javascript   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!