首页 > 解决方案 > 结果:语法错误 json 解析错误:无法识别的令牌 '<'

问题描述

我正在研究 React Native 项目 Fetching API 我在屏幕 “JSON Parse error: Unrecognized token '<'”中收到此错误。我想使用 asp.net webservice 在项目中插入一些字段

这是我的代码:

 registerCall(){
       var that = this;
       var url = "http://xxxxx/products.asmx/Registration";
        console.log("url:"+url);
    
        const { TextInputName }  = this.state.user_name ;
     const { TextInputEmail }  = this.state.email ;
      const { TextInputPassword }  = this.state.email ;
     const { Textmobile_no }  = this.state.mobile_no ;
    
     fetch(url, {
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
    
        user_name: TextInputName,
    
        password: TextInputPassword,
    
        email: TextInputEmail,
    
        mobile_no: Textmobile_no
    
      })
             }).then(function (response) {
    
               return response.json();
             }).then(function (result) { 
          
               if(!result.error){
                that.setState({ status: result.error,
                                wholeResult: result,
                             });
                Alert.alert("User register successfully \n userId: "+that.state.wholeResult.user.uid);
                console.log(that.state.wholeResult.user.uid);
            }else{
             Alert.alert(result.error_msg);
             console.log(result);
       }
    }).catch(function (error) {
       console.log("-------- error ------- "+error);
       alert("result:"+error)
     });
    }

看这里我的屏幕截图

网络服务 。CS

这是我的 Web 服务代码:

  [WebMethod]
    public void Registration(string name, string password, string email, long mobileno)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        using (SqlCommand cmd = new SqlCommand("INSERT INTO registration(user_name,password,email,mobile_no) VALUES(@name,@password,@email,@mobileno)", con))
        {
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.AddWithValue("@name", name);
            cmd.Parameters.AddWithValue("@password", password);
            cmd.Parameters.AddWithValue("@email", email);
            cmd.Parameters.AddWithValue("@mobileno", mobileno);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }

    }

标签: androidjsonreactjsreact-nativeweb-services

解决方案


推荐阅读