代码之家  ›  专栏  ›  技术社区  ›  novafluff

反应本机铁路超高日志特定部分

  •  2
  • novafluff  · 技术社区  · 7 年前

    好的,我觉得我有一个特殊的问题,就是反应

    这是代码

           login(){
        fetch('http://52.28.212.104:8081/milltimeLogin', {
                method: 'POST',
                headers: {
                    'Authorization':"basic " + this.state.username + ":" + this.state.passw ,
                },
        }).then(response => response.text())
              .then(text => {
                console.log(text['mta:loginResponse']);
    
              })
    }
    

    这个确切的日志在reactjs中有效,但在react native中无效。我之所以使用['mta:…']是因为响应有mta:tags,所以我必须使用['',但我似乎在react native中无效。如果我只记录文本,我会得到整个响应,但我需要得到它的特定部分。有人知道如何在react native中做到这一点吗?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Val    7 年前

    我认为你可以这样做,把它理解为 json 对象,但不包括 text .

    login(){
      fetch('http://52.28.212.104:8081/milltimeLogin', {
        method: 'POST',
        headers: {
          'Authorization':"basic " + this.state.username + ":" + this.state.passw ,
        },
    }).then(response => response.json())
        .then(json => {
          console.log(json['mta:loginResponse']);
        })
    }
    
        2
  •  0
  •   Danish Hassan    5 年前

    而不是使用简单的控制台。log命令

    使用Reactoron记录数据 以下是链接: https://github.com/infinitered/reactotron

    日志的最佳选择