android - 结果:语法错误 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();
}
}
解决方案
推荐阅读
- javascript - 如何使用 document.write 更改文本并删除过去的文本
- android-studio - 更新到 Android Studio 4.1.1
- rust - 如何编写一个宏来返回基于字符串的结构的实现方法?
- r - 另一个向量中特定对象的向量中的第二大值
- mysql - 如何根据第 1 列的值仅获取第 2 列的唯一值?
- php - 使用 laravel api 在 swoole 上启用 https
- python - new_row = dict.fromkeys(df, 0) 语句的问题
- javascript - 使用 react-pdf 和 pdfjs 从 PDF blob 创建图像列表
- python - CV2 和 Pillow 给出不同的图像形状
- python - 如何使用 Python 在 H2o 库中重用带有 GBM 的 cross_validation_fold_assignment()