0

Hello I need a solution for multiple json post through react native since I'm new in React native. Here is my new json data I need to post

[
  {
    "rollno": "10",
    "typeofattendence": 1
  },
  {
    "rollno": "10021",
    "typeofattendence": 0
  }
]

Here is my fetch data please note I can post single json data not able to post multiple.Here is my code

body: JSON.stringify({
        rollno: this.state.data,
        typeofattendence: this.state.value
      })`      `body: JSON.stringify({
        rollno: this.state.data,
        typeofattendence: this.state.value
      })

Please help me . Here you can see I can post single json object but how i post inside array multiple object . Thanks in advance

2 Answers 2

1

You should store your object in an array first. For example.

let data = [];
data.push({
 rollno: this.state.data,
 typeofattendence: this.state.value
});

and when you want to send it to the server

body: JSON.stringify(data);
Sign up to request clarification or add additional context in comments.

3 Comments

how i declare let data inside flatlist because data is in flatlist and renderitem
your code is for sending data not receiving it. renderItem is for displaying data (render the item), if you want to parse data inside renderItem, you should use JSON.parse(yourData). You can declare variable inside renderItem function or call another function inside that.
yes i want post from renderdata I get some data and want to post and data is multiple
0

You can use:

var myarray = [];
var myJSON = "";

var item = {
    "rollno": "10",
    "typeofattendence": 1
  };

myarray.push(item);

item = {
    "rollno": "10021",
    "typeofattendence": 0
  }
myarray.push(item);

myJSON = JSON.stringify({myarray: myarray});

As this http://jsfiddle.net/jensbits/MWSeg/ toturial says.

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.