On Feb 21, 2016, at 10:58 PM, Duy Nguyen <
nguyen...@gmail.com> wrote:
> On Mon, Feb 22, 2016 at 10:34 AM, Aria Stewart <
ared...@dinhe.net> wrote:
>
>> On Feb 21, 2016, at 21:47, Duy Nguyen <
nguyen...@gmail.com> wrote:
>>
>>> I'm developing rest service using Express framework, I used Postman to test this web service, but I got this headache scenario need your help.
>>> 1. api method: /contents (POST)
>>> 2. request body (on Postman) (x-www-form-urlencoded):
>>> contents[0] : {file_name: 'abc.txt'}
>>> contents[1]: {file_name: 'xyz.txt'}
>>> 3. server:
>>> var contents = req.body.contents;
>>> console.log(contents[0]); //can see value here in string format with all information
>>> console.log(contents[0].file_name); // undefined??
>>
>> contents[0] is a string -- if you want to parse it to see it as an object, JSON.parse it.
>
Correct, your strings are valid JavaScript, but *NOT* valid JSON. For it to be valid JSON, the attribute values have to be "double-quoted", not 'single-quoted'. The attribute names also have to be "double-quoted" instead of not quoted at all.