Reputation: 482
Which is the correct way for sending POST response for webservices for Android app.
METHOD #1 : Send As Array
[
{
"Field1":1,
"Field2":1,
"Field3":{
"Field4":1,
"Field5":"Restaurant"
},
"Field6":"xyz",
"Field7":null,
}
]
METHOD #2 : Send As Object
{
"Message":"Good",
"Result":[
{
"Field1":1,
"Field2":1,
"Field3":{
"Field4":1,
"Field5":"Restaurant"
},
"Field6":"xyz",
"Field7":null
}
]
}
Upvotes: 0
Views: 58
Reputation: 4371
That purely depends upon your requirement.
Having an array in Method 1 removes extra object creation for parsing the request.
Where as in some cases if your application include other webservice calls which follow different standard for status management like others commented, it's better to follow that only. Method 2 definitely includes error management and more preferred.
Upvotes: 2
Reputation: 3134
Obviously 2nd one
Step 1 for every operation, we need to know- "Is there any error or got success !".
Step 2 Now get the "data section" or "Error message".
Upvotes: 1
Reputation: 360
Method 2: send As Object is good enough. In this way developers can check the status of that response from your message.
Upvotes: 1
Reputation: 6622
I suggest you have to got with second one with one more params like status
true/false
so you can identify your status based on it.
Upvotes: 1