This forum allows users to post and respond to "How Do I Do ....." questions. The information contained in this forum has not been validated by K-Rise Systems and, as such, K-Rise Systems cannot guarantee the accuracy of the information.
JefferyD
Posts: 178 Joined: August 31st, 2021, 11:37 am
Contact:
Unread post
by JefferyD » February 24th, 2022, 9:45 am
I'm working on making REST APIs, but I'm having a little difficulty making the response consistent.
This is how the response returns normally.
Code: Select all
{
"Response": {
"Employees": {
"Employee": [
{
"ContractorFormID": "1114",
"ContractorAddressBookNum": ""
},
{
"ContractorFormID": "1116",
"ContractorAddressBookNum": ""
}
]
}
}
}
When only a single employee is returned though, it's no longer in an array.
Code: Select all
{
"Response": {
"Employees": {
"Employee": {
"ContractorFormID": "1114",
"ContractorAddressBookNum": ""
}
}
}
}
Is there any way to force it be an array like this?
Code: Select all
{
"Response": {
"Employees": {
"Employee": [
{
"ContractorFormID": "1114",
"ContractorAddressBookNum": ""
}
]
}
}
}
Last edited by
JefferyD on March 15th, 2022, 5:33 pm, edited 1 time in total. word count: 82
Tags:
SteveCap
Posts: 329 Joined: August 26th, 2021, 9:18 am
Contact:
Unread post
by SteveCap » February 24th, 2022, 10:45 am
Is this created as xml?
If so you can try adding in an attribute.
Code: Select all
<Employees>
<Employee json:Array="True">
<ContractorFormID></ContractorFormID>
<ContractorAddressBookNum></ContractorAddressBookNum>
</Employee>
</Employees>
Or
Code: Select all
<Employees>
<Employee jsonArray="True">
<ContractorFormID></ContractorFormID>
<ContractorAddressBookNum></ContractorAddressBookNum>
</Employee>
</Employees>
word count: 42
JefferyD
Posts: 178 Joined: August 31st, 2021, 11:37 am
Contact:
Unread post
by JefferyD » February 24th, 2022, 11:21 am
word count: 83
SteveCap
Posts: 329 Joined: August 26th, 2021, 9:18 am
Contact:
Unread post
by SteveCap » February 24th, 2022, 12:00 pm
I did some test on my own. You need to also add in the namespace so either of these should work.
Code: Select all
<Employees>
<Employee json:Array="true" xmlns:json="http://james.newtonking.com/projects/json">
<ContractorFormID></ContractorFormID>
<ContractorAddressBookNum></ContractorAddressBookNum>
</Employee>
</Employees>
OR
Code: Select all
<Employees>
<Employee jsonArray="true" xmlns:json="http://james.newtonking.com/projects/json">
<ContractorFormID></ContractorFormID>
<ContractorAddressBookNum></ContractorAddressBookNum>
</Employee>
</Employees>
word count: 65
JefferyD
Posts: 178 Joined: August 31st, 2021, 11:37 am
Contact:
Unread post
by JefferyD » February 24th, 2022, 3:53 pm
Thanks, that worked exactly as I needed it to.
word count: 9