从服务器获取错误“消息”:“意外的令牌d”

时间:2016-12-14 19:25:11

标签: angularjs json node.js mongoose

当从浏览器发送请求时,我从服务器收到错误500,而当邮递员发送请求时收到400错误。以下是我的JSON

{ dishes:
   [ { _id: '584ae32eb4e5ec277c8dbcab',
       name: 'Uthapizza',
       price: 499,
       image: 'images/uthapizza.png' },
     { _id: '584ae346b4e5ec277c8dbcb1',
       name: 'Zucchipakoda',
       price: 199,
       image: 'images/zucchipakoda.png' },
     { _id: '584ae359b4e5ec277c8dbcb7',
       name: 'Vadonut',
       price: 199,
       image: 'images/vadonut.png' } ],
  sum: 8.97,
  postedBy: '584ae0ca2e678112b03f8a47',
  _id: 58519897c777f922646a5215 }

关联的mongoose架构是

var orderSchema = new Schema({
    dishes: [ {
        _id: {
            type: mongoose.Schema.Types.ObjectId,
            required: true,
            unique: true
        },
        name: {
            type: String,
            required: true,
            unique: true
        },
        price: {
            type: Currency,
            required: true
        },
        image: {
            type: String,
            required: true
        }
    }
    ],
    sum: 
    {
        type: Currency,
        required: true
    },
    postedBy: 
    {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User'
    }
},
{
        timestamps: true
});

我不确定是什么问题。谢谢你的时间

的问候, 拉吉

1 个答案:

答案 0 :(得分:0)

它不是有效的const Logo = function(props) { const styles = (props.modal ? 'logo logo--xs' : 'hide'); return ( <div> <img src={props.logo} className={styles} alt="I-Spell-Its logo" /> </div> ); }; const Score = function(props) { const styles = (props.modal ? 'hide' : props.styles) const text = (props.text ? <strong>{props.text}</strong> : ''); return ( <p className={styles}> {text} {props.score} pts </p> ); }; const Lives = function(props) { const styles = (props.modal ? 'hide' : 'lives lives--left') return ( <p className={styles}> Lives: {props.lives} </p> ); }; export { Score, Logo, Lives };

  • json字符串被双引号括起来。
  • 键也不有效(不是有效值:没有双引号的字符串)

请注意,它是json,而不是json

这是一个有效的json文档:

JavaScript