【发布时间】:2020-07-15 11:02:40
【问题描述】:
我在使用 json.stringify 时遇到问题,它返回一个 json,在 json 后面有一个冒号
axios.post('http://54.196.61.131/api/v0/user/250/product/add/scan',
JSON.stringify({
name: currentProduct.product.product_name_fr,
brand: currentProduct.product.brands,
image: currentProduct.product.image_front_thumb_url,
product_quantity: currentProduct.product.quantity,
ingredients: currentProduct.product.ingredients_text,
quantity: parseInt(quantite, 10),
nutriscore_grade: currentProduct.product.nutriscore_grade,
expiration_date: expDate,
barcode: currentProduct.code,
}))
它最后返回一个 :,所以我的 API 出现 500 错误:
{"name":"Farine de blé suprême","brand":"Francine","image":"https://static.openfoodfacts.org/images/products/306/811/070/3232/front_fr.37.100.jpg","product_quantity":"1 kg","ingredients":"Farine de blé type 45.","quantity":6,"nutriscore_grade":"a","barcode":"3068110703232","expiration_date":"2020-07-24T10:41:04.000Z"}:
谢谢
【问题讨论】:
-
不,不会,因为这不是有效的 JSON。请添加显示实际问题的minimal reproducible example(最好是runnable snippet
<>)。 -
尝试控制台记录数据,它是字符串化的形式,通常在字符串化结束后你永远不会得到冒号。
标签: javascript json reactjs