Failed to parse response using consume rest api

Failed to parse response using consume rest api

  

Hi,

Please help us to find the solution on our problem. Basically the error will only prompt if our response has only single MemberDetails but if our response have more than 1 MemberDetails we successfully get the value of our response. Please see the sample response below.


Single MemberDetails

"MemberDetails": {
    "CardType": "x3mg7XRCPCQ=",
    "CardNumber": "lZGxPyJd4rA6sKdRTD4fYEaezOjEOdpx"
  }


More than MemberDetails

"MemberDetails": [
{
"CardType": "x3mg7XRCPCQ=",
"CardNumber": "lZGxPyJd4rCD0+p6AXt/TkaezOjEOdpx"
},
{
"CardType": "x3mg7XRCPCQ=",
"CardNumber": "lZGxPyJd4rDIf7zOVGWU1UaezOjEOdpx"
}
]

Hi, since the JSON structure is not consistent, you will get the error.

If you can change your rest api server, it will better if it outputs consistent structure even if result is just 1.

"MemberDetails": [{
    "CardType": "x3mg7XRCPCQ=",
    "CardNumber": "lZGxPyJd4rA6sKdRTD4fYEaezOjEOdpx"
  }]


If you can't do that, then do:

1. set response format to Plain Text

2. set Response output parameter data type to Text.

3. in your logic, after calling this rest api method, use If condition to check if result is 1 or more

you can search array characters "[" or "]"   ***beware if your content has that chars too***

or you can count how many CardType string in in your output.

4. prepare 2 structures: 1 for single result, 1 for multiple result

5. use 2 JSONDeserialize based on if condition.

use different structure in Data Type for single result and multiple result

hi Reuben,

why not make it same structure with the second one:

"MemberDetails": [
{
"CardType": "x3mg7XRCPCQ=",
    "CardNumber": "lZGxPyJd4rA6sKdRTD4fYEaezOjEOdpx"

}
]


regards,

M

Harlin Setiadarma wrote:

Hi, since the JSON structure is not consistent, you will get the error.

If you can change your rest api server, it will better if it outputs consistent structure even if result is just 1.

"MemberDetails": [{
    "CardType": "x3mg7XRCPCQ=",
    "CardNumber": "lZGxPyJd4rA6sKdRTD4fYEaezOjEOdpx"
  }]


If you can't do that, then do:

1. set response format to Plain Text

2. set Response output parameter data type to Text.

3. in your logic, after calling this rest api method, use If condition to check if result is 1 or more

you can search array characters "[" or "]"   ***beware if your content has that chars too***

or you can count how many CardType string in in your output.

4. prepare 2 structures: 1 for single result, 1 for multiple result

5. use 2 JSONDeserialize based on if condition.

use different structure in Data Type for single result and multiple result

Hi,

I already followed your instruction and it seems that i already get the response for single and multiple records. But i encountered another problem. When i add dropdown widget and if my record is single i encountered this error below. Thanks



That's because dropdown widget expect a List (array), not a single element.

You need to create a local variable with List datatype with same structure.

After JSONDeserializeSingleOutput, add ListAppend client action.

Append JSONDeserializeSingleOutput output to local variable.

Use that local variable as dropdown source list.

Harlin Setiadarma wrote:

That's because dropdown widget expect a List (array), not a single element.

You need to create a local variable with List datatype with same structure.

After JSONDeserializeSingleOutput, add ListAppend client action.

Append JSONDeserializeSingleOutput output to local variable.

Use that local variable as dropdown source list.

Hi,  

Thank you for the information. 

My problem in single and multiple element using dropdown widget is already solved. 

Thank you very much for the support.