<small id='VeJgS'></small><noframes id='VeJgS'>

<i id='VeJgS'><tr id='VeJgS'><dt id='VeJgS'><q id='VeJgS'><span id='VeJgS'><b id='VeJgS'><form id='VeJgS'><ins id='VeJgS'></ins><ul id='VeJgS'></ul><sub id='VeJgS'></sub></form><legend id='VeJgS'></legend><bdo id='VeJgS'><pre id='VeJgS'><center id='VeJgS'></center></pre></bdo></b><th id='VeJgS'></th></span></q></dt></tr></i><div id='VeJgS'><tfoot id='VeJgS'></tfoot><dl id='VeJgS'><fieldset id='VeJgS'></fieldset></dl></div>
  • <legend id='VeJgS'><style id='VeJgS'><dir id='VeJgS'><q id='VeJgS'></q></dir></style></legend>

          <bdo id='VeJgS'></bdo><ul id='VeJgS'></ul>

        <tfoot id='VeJgS'></tfoot>
      1. 从 ReadableStream 对象中检索数据?

        时间:2023-10-02
      2. <legend id='SMD5u'><style id='SMD5u'><dir id='SMD5u'><q id='SMD5u'></q></dir></style></legend>

      3. <small id='SMD5u'></small><noframes id='SMD5u'>

                <i id='SMD5u'><tr id='SMD5u'><dt id='SMD5u'><q id='SMD5u'><span id='SMD5u'><b id='SMD5u'><form id='SMD5u'><ins id='SMD5u'></ins><ul id='SMD5u'></ul><sub id='SMD5u'></sub></form><legend id='SMD5u'></legend><bdo id='SMD5u'><pre id='SMD5u'><center id='SMD5u'></center></pre></bdo></b><th id='SMD5u'></th></span></q></dt></tr></i><div id='SMD5u'><tfoot id='SMD5u'></tfoot><dl id='SMD5u'><fieldset id='SMD5u'></fieldset></dl></div>

                <tfoot id='SMD5u'></tfoot>
                  <tbody id='SMD5u'></tbody>
                • <bdo id='SMD5u'></bdo><ul id='SMD5u'></ul>

                • 本文介绍了从 ReadableStream 对象中检索数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何从 ReadableStream 对象获取信息?

                  How may I get information from a ReadableStream object?

                  我正在使用 Fetch API,但我没有从文档中看到这一点.

                  I am using the Fetch API and I don't see this to be clear from the documentation.

                  正文作为 ReadableStream 返回,我只想访问此流中的属性.在浏览器开发工具的响应下,我似乎将这些信息组织成属性,以 JavaScript 对象的形式.

                  The body is being returned as a ReadableStream and I would simply like to access a property within this stream. Under Response in the browser dev tools, I appear to have this information organised into properties, in the form of a JavaScript object.

                  fetch('http://192.168.5.6:2000/api/car', obj)
                      .then((res) => {
                          if(res.status == 200) {
                              console.log("Success :" + res.statusText);   //works just fine
                          }
                          else if(res.status == 400) {
                              console.log(JSON.stringify(res.body.json());  //res.body is undefined.
                          }
                  
                          return res.json();
                      })
                  

                  推荐答案

                  为了从 ReadableStream 访问数据,您需要调用其中一种转换方法(可用文档 这里).

                  In order to access the data from a ReadableStream you need to call one of the conversion methods (docs available here).

                  举个例子:

                  fetch('https://jsonplaceholder.typicode.com/posts/1')
                    .then(function(response) {
                      // The response is a Response instance.
                      // You parse the data into a useable format using `.json()`
                      return response.json();
                    }).then(function(data) {
                      // `data` is the parsed version of the JSON returned from the above endpoint.
                      console.log(data);  // { "userId": 1, "id": 1, "title": "...", "body": "..." }
                    });
                  


                  如果您的数据返回类型不是 JSON,或者您不想要 JSON,请使用 text()


                  If your data return type is not JSON or you don't want JSON then use text()

                  举个例子:

                  fetch('https://jsonplaceholder.typicode.com/posts/1')
                    .then(function(response) {
                      return response.text();
                    }).then(function(data) {
                      console.log(data); // this will be a string
                    });
                  

                  希望这有助于解决问题.

                  Hope this helps clear things up.

                  这篇关于从 ReadableStream 对象中检索数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:fetch 即使 404 也能解决? 下一篇:redux fetch body 在没有 cors 模式的情况下不使用

                  相关文章

                  1. <tfoot id='X70Bd'></tfoot>

                      <small id='X70Bd'></small><noframes id='X70Bd'>

                    1. <i id='X70Bd'><tr id='X70Bd'><dt id='X70Bd'><q id='X70Bd'><span id='X70Bd'><b id='X70Bd'><form id='X70Bd'><ins id='X70Bd'></ins><ul id='X70Bd'></ul><sub id='X70Bd'></sub></form><legend id='X70Bd'></legend><bdo id='X70Bd'><pre id='X70Bd'><center id='X70Bd'></center></pre></bdo></b><th id='X70Bd'></th></span></q></dt></tr></i><div id='X70Bd'><tfoot id='X70Bd'></tfoot><dl id='X70Bd'><fieldset id='X70Bd'></fieldset></dl></div>

                      • <bdo id='X70Bd'></bdo><ul id='X70Bd'></ul>
                    2. <legend id='X70Bd'><style id='X70Bd'><dir id='X70Bd'><q id='X70Bd'></q></dir></style></legend>