aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/response/json/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2021-07-16 16:27:00 -0400
committerGitHub <noreply@github.com>2021-07-17 04:27:00 +0800
commitb9afb23d12dcae1e09f8d04c72143c5ddaa34aea (patch)
treef6c20844119bcaf0131ad4a037e0245577927f2c /files/zh-cn/web/api/response/json/index.html
parent1aa671566c3a990ec2df9a46137471d624b6f7ff (diff)
downloadtranslated-content-b9afb23d12dcae1e09f8d04c72143c5ddaa34aea.tar.gz
translated-content-b9afb23d12dcae1e09f8d04c72143c5ddaa34aea.tar.bz2
translated-content-b9afb23d12dcae1e09f8d04c72143c5ddaa34aea.zip
delete conflicting/orphaned docs (zh-CN) (#1412)
* delete conflicting docs (zh-CN) * and redirects * do orphaned as well * fix * remove more orphans * revert orphaned docs that can identify origin * move orphaned docs to current loc * adjust slug path * fix redirect change from rebase Co-authored-by: Irvin <irvinfly@gmail.com>
Diffstat (limited to 'files/zh-cn/web/api/response/json/index.html')
-rw-r--r--files/zh-cn/web/api/response/json/index.html91
1 files changed, 91 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/response/json/index.html b/files/zh-cn/web/api/response/json/index.html
new file mode 100644
index 0000000000..360c349054
--- /dev/null
+++ b/files/zh-cn/web/api/response/json/index.html
@@ -0,0 +1,91 @@
+---
+title: Response.json()
+slug: Web/API/Response/json
+translation_of: Web/API/Response/json
+tags:
+ - API
+ - Fetch
+ - JSON
+ - Method
+ - Reference
+ - Response
+browser-compat: api.Response.json
+---
+<div>{{APIRef("Fetch")}}</div>
+
+<div>{{domxref("Response")}}  mixin 的 <strong><code>json()</code></strong> 方法接收一个 {{domxref("Response")}} 流,并将其读取完成。它返回一个 Promise,Promise 的解析 resolve 结果是将文本体解析为 {{jsxref("JSON")}}。</div>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">response.json().then(data =&gt; {
+ // do something with your data
+});</pre>
+
+<h3 id="参数">参数</h3>
+
+<p>没有。</p>
+
+<h3 id="返回值">返回值</h3>
+
+<p>返回一个被解析为<a href="https://developer.mozilla.org/zh-CN/docs/Web/API/JSON" title="此页面仍未被本地化, 期待您的翻译!"><code>JSON</code></a>格式的promise对象,这可以是任何可以由JSON表示的东西 - 一个object,一个array,一个string,一个number...</p>
+
+<h2 id="示例">示例</h2>
+
+<p>在我们的  <a href="https://github.com/mdn/fetch-examples/tree/master/fetch-json">fetch json 示例</a> 中(运行 <a href="http://mdn.github.io/fetch-examples/fetch-json/">fetch json live</a>), 我们使用 {{domxref("Request.Request")}} 构造函数创建一个新的请求, 然后使用它来获取一个 <code>.json</code> 文件。当获取成功时,我们使用 <code>json()</code> 读取并解析数据,然后像预期的那样从结果对象中读取值,并将其插入到列表项中以显示我们的产品数据。</p>
+
+<pre class="brush: js highlight[5]">const myList = document.querySelector('ul');
+const myRequest = new Request('products.json');
+
+fetch(myRequest)
+ .then(response =&gt; response.json())
+ .then(data =&gt; {
+ for (const product of data.products) {
+ let listItem = document.createElement('li');
+ listItem.appendChild(
+ document.createElement('strong')
+ ).textContent = product.Name;
+ listItem.append(
+ ` can be found in ${
+ product.Location
+ }. Cost: `
+ );
+ listItem.appendChild(
+ document.createElement('strong')
+ ).textContent = `£${product.Price}`;
+ myList.appendChild(listItem);
+ }
+ });</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName("Fetch", "#dom-body-json", "Response.json()")}}</td>
+ <td>{{Spec2("Fetch")}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.Response.json")}}</p>
+
+<h2 id="相关链接">相关链接</h2>
+
+<ul>
+ <li><a href="/zh-CN/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
+ <li><a href="/zh-CN/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li>
+ <li><a href="/zh-CN/docs/Web/HTTP">HTTP</a></li>
+</ul>