当我尝试在我的服务器(node.js)上发布信息时,我遇到了一些问题。 我的阵列是:
order[0] = {orderID:"0", customerOrderRef:"Mary", albums: { numberOfPhotos: "1", citation:"sing", photo
{photoPath: "here"}, qty: "1"}, deliveryAddress: {street: "poland street",
doorNumber:"100", zipCode:"5555", city:"London", country: "England"}, status: "waiting",
createdOn: now};
当我尝试发布信息时:
.post(function(req, res) {
console.dir(req.body);
orderCount++;
orders[orderCount] = buildMessage(orderCount,req.body.customerOrderRef,req.body.numberOfPhotos,req.body.citation,req.body.photoPath,req.body.qty,req.body.street,req.body.doorNumber,req.body.zipCode,req.body.country);
res.status(201).set('Location', SERVER_ROOT + "/PrintingOrder/" + orderCount).json(orders[orderCount]);
})
和我的buildmessage函数
function buildMessage(newID, user, numberOfPhotos, citation, photoPath, qty, street,doorNumber, zipCode, city, country){
return {
orderID : newID,
customerOrderRef : user,
numberOfPhotos: numberOfPhotos,
citation: citation,
photoPath: photoPath,
qty: qty,
street: street,
doorNumber: doorNumber,
zipCode: zipCode,
country: country,
status: "waiting"
};
};
当我尝试POST信息时,这很好用。但是,信息不会出现在数组中的第一个值(数组内的对象)的相同命名。
我的期望:
{
"orderID": "0",
"customerOrderRef": "Mary",
"albums": {
"numberOfPhotos": "1",
"citation": "home sweet home",
"photo": {
"photoPath": "here"
},
"qty": "1"
},
"deliveryAddress": {
"street": "street",
"doorNumber": "100",
"zipCode": "5555",
"city": "London",
"country": "England"
},
"status": "waiting",
"createdOn": "2015-01-02T12:45:35.034Z"
}
我实际获得的是:
{
"orderID": 1,
"customerOrderRef": "Jane",
"numberOfPhotos": "2",
"citation": "test",
"photoPath": "test",
"qty": "2",
"street": "street",
"doorNumber": "111",
"status": "waiting"
}