1

I have a json file in my android local device, im able to read and edit the json file and store json data in it. But the problem is arising when i want to insert new element in the json file. Im able to change the value of existing variables. the json file data is:

var data = {items: 
{id: "1", name: "Snatch", type: "crime"}
};

i want to add one more element to it so that json file will look like

var data = {items: [
{id: "1", name: "Snatch", type: "crime"},
{id: "7", name: "Douglas Adams", type: "comedy"}
};

i tried with

data.items.push{id: "7", name: "Douglas Adams", type: "comedy"}

but its not working.

im creating android app using phonegap framework with telerik IDE.

Sandeep
  • 1,504
  • 7
  • 22
  • 32

1 Answers1

1

Try

data.items.push(
    {id: "7", name: "Douglas Adams", type: "comedy"}
);

You are missing ()

Your first file example is missing []

Check out this links to know more about json addition and removal Link 1 , Link 2

Community
  • 1
  • 1
AtanuCSE
  • 8,832
  • 14
  • 74
  • 112