javascript - 我将如何通过 jQuery 解析多个或更多对象?
问题描述
像这样
► add language identifier to highlight code
```python
def function(foo):
print(foo)
► 在段落之间放置返回
► 对于换行符,在末尾添加 2 个空格
►斜体或粗体
► 代码缩进 4 个空格
► 反引号转义like _so_
► 通过在行首放置 > 来引用
► 建立链接(尽可能使用 https )https://example.com 示例
解决方案
正如@Pointy 所提到的,您的代码中有多个语法错误(访问obj
数组时)。
但是即使在您修复了这些语法错误之后它也无法工作的原因是您的 API 调用的结果是一个字符串,您需要使用JSON.parse()
.
$.get('https://raw.githubusercontent.com/danielhoset27/test1/master/C2RReleaseData.json', function(obj) {
// Parse the received json
const result = JSON.parse(obj);
// Fix the syntax errors
document.writeln(result[0].FFN + " : " + result[0].AvailableBuild);
// Add a line break
document.write('<br />')
// Fix the syntax errors again
document.writeln(result[1].FFN + " : " + result[1].AvailableBuild);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
还要考虑使用Fetch API是您的目标浏览器支持它。
const appendItem = item => document.body.innerHTML += `<p>${item.FFN} : ${item.AvailableBuild}</p>`;
fetch('https://raw.githubusercontent.com/danielhoset27/test1/master/C2RReleaseData.json').then(response => {
response.json().then(result => {
appendItem(result[0]);
appendItem(result[1]);
});
});
推荐阅读
- php - (PHP) Ixudra/Curl 无法发布文件
- sql - 将两个sql行合二为一
- python - 何使用芹菜工人
- angular - 如何使可观察的 debounceTime 有条件
- javascript - 单独预览多个上传的图像
- django - django 内置 password_reset 从 send_email 更改连接
- python - Scrapy下一页链接没有给出任何内容
- javascript - WordPress AJAX 不显示内容
- php - .htaccess:从公共目录中提供静态文件,而不在 URL 中公开,否则重写为 index.php
- spring-boot - 将应用程序升级到 springboot 2.0.4.RELEASE 后应用程序无法运行