[英]React Native- JSON Parse error: Unexpected identifier “no”
下面是ViewProducts.js中的fething代碼
componentDidMount() {
return fetch('http://192.168.0.109/fyp/products.php')
.then((response) => response.json())
.then((responseJson) => {
let ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
this.setState({
isLoading: false,
dataSource: ds.cloneWithRows(responseJson),
}, function() {
});
})
.catch((error) => {
console.error(error);
});
}
如果您遇到錯誤且不是json_encoded,通常會發生這種情況。 嘗試捕獲您收到的所有錯誤並回顯Json響應例如,mysql插入錯誤可以按如下方式處理
if ($conn->query($sql) === TRUE) {
// If the record inserted successfully then show the message.
$MSG = "New record created successfully";
// Converting the message into JSON format.
$json = json_encode($MSG);
// Echo the message.
echo $json;
} else {
$errorMsg="Error: " . $sql . "<br>" . $conn->error;
$json = json_encode($errorMsg);
echo $json;
}
否則你可以共享你的服務器代碼,將有助於排除故障!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.