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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.