com.facebook.react.bridge.readablenativemap无法强制转换为java.lang.string

时间:2018-05-31 11:17:37

标签: react-native fetch multipartform-data

我的代码:

  const file = {
    uri: this.state.imageSource,
    name: this.state.imageName,
    type: "image/jpg"
  }
  const data = new FormData();
  data.append("file", file);

  fetch(config.server + "/upload", {
    method: "POST",
    body: data
  })
    .then(res => res.json())
    .then(responseData => {
      alert(JSON.stringify(responseData));
    })
    .catch(err => {
      alert(err);
    });

没有 FormData 代码不显示错误。我应该怎么做才能解决?在android上调试。

6 个答案:

答案 0 :(得分:4)

错误是因为我将URL作为数组传递,但是它需要一个字符串。

答案 1 :(得分:1)

我收到此错误是因为我的网址不正确

答案 2 :(得分:0)

就我而言,我没有运行api服务器。

答案 3 :(得分:0)

这将解决问题: alert(JSON.stringify(data))

答案 4 :(得分:0)

react-native link

使用此命令解决此问题。这对我有用。

注意:仅适用于本机<60.x

答案 5 :(得分:-1)

我也遇到了同样的问题,下面的代码行可以解决。

def pick_question():
    Table = random.randint(0,9)
    Col = random.randint(0,9)
    if Table == 0:
        if Col == 0:
            return Tone[0]
        elif Col == 1:
            return Tone[1]
        elif Col == 2:
            return Tone[2]
        elif Col == 3:
            return Tone[3]
        elif Col == 4:
            return Tone[4]
        elif Col == 5:
            return Tone[5]
        elif Col == 6:
            return Tone[6]
        elif Col == 7:
            return Tone[7]
        elif Col == 8:
            return Tone[8]
        elif Col == 9:
            return Tone[9]
    elif Table == 1:
        if Col == 0:
            return Ttwo[0]
        elif Col == 1:
            return Ttwo[1]
        elif Col == 2:
            return Ttwo[2]
        elif Col == 3:
            return Ttwo[3]
        elif Col == 4:
            return Ttwo[4]
        elif Col == 5:
            return Ttwo[5]
        elif Col == 6:
            return Ttwo[6]
        elif Col == 7:
            return Ttwo[7]
        elif Col == 8:
            return Ttwo[8]
        elif Col == 9:
            return Ttwo[9]