使用JavaScript读取JSON [英] Reading out JSON using JavaScript

查看:99
本文介绍了使用JavaScript读取JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出了以下JSON文件:

given is following JSON-File:

{
   "name": "yiisoft/yii2-app-advanced",
   "description": "Yii 2 Advanced Project Template",
   "keywords": ["yii2", "framework", "advanced", "project template"],
   "homepage": "http://www.yiiframework.com/",
   "type": "project",
   "license": "BSD-3-Clause",
   "support": {
       "issues": "https://github.com/yiisoft/yii2/issues?state=open",
       "forum": "http://www.yiiframework.com/forum/",
       "wiki": "http://www.yiiframework.com/wiki/",
       "irc": "irc://irc.freenode.net/yii",
       "source": "https://github.com/yiisoft/yii2"
   },
   "minimum-stability": "dev",
   "require": {
       "php": ">=5.4.0",
       "yiisoft/yii2": "~2.0.6",
       "yiisoft/yii2-bootstrap": "~2.0.0",
       "yiisoft/yii2-swiftmailer": "~2.0.0"
   },
   "require-dev": {
       "yiisoft/yii2-debug": "~2.0.0",
       "yiisoft/yii2-gii": "~2.0.0",
       "yiisoft/yii2-faker": "~2.0.0",
       "codeception/base": "^2.2.3",
       "codeception/verify": "~0.3.1"
   },
   "config": {
       "process-timeout": 1800
   },
   "repositories": [
       {
           "type": "composer",
           "url": "https://asset-packagist.org"
       }
   ]
}

如何读取属性最小稳定性? 以下代码因抛出错误而失败:qnips_JSON_Loesung.html:112未捕获的ReferenceError:未定义稳定性

How to read out property minimum-stability? Following code fails by throwing out error:qnips_JSON_Loesung.html:112 Uncaught ReferenceError: stability is not defined

output+="<th class='spalte'>"+daten.minimum-stabilty+"</th></tr>";

顺便说一句,下面的构造工作得很好:

By the way, following construct works quite fine:

output+="<th class='spalte'>"+daten.keywords+"</th></tr>";

推荐答案

以下代码解决了我的问题:

Following code solved my problem:

for(let j in daten["require-dev"]){
output+="<label> Version "+daten["require-dev"][j]+"<br></label>";
}

这篇关于使用JavaScript读取JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆