Graziano Dimatteo Graziano Dimatteo - 1 year ago 141
Node.js Question

Nodejs how to use map of object?

Hi i have a json like this called body:

{data: {id:1, name:hallo},
{next: "abc" }

so i have to save it into a map and then i ll need to print or to modify it.
If i save it with this code

var Map = require("collections/map");

var new_body = JSON.parse(body)
var map = new Map(new_body);

i have some difficulties to print for example, how can i do it? maybe i had to define a structure of that map before inserting the json inside it, i don't know...

Answer Source

Your json have errors. Correct them like this.

  "data": {
    "id": 1,
    "name": "hallo"
  "paging": {
    "cursors": {
      "next": "abc"

Then you can parse the json like this and get the value.

var map = JSON.parse(body);//This will parse the json string

Now will have the value "abc"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download