最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

在 nodejavascript 中解析 JSON

网站源码admin36浏览0评论

在 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');

希望对您有所帮助。

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论