X Yz
Posts: 0
Joined: Tue Feb 10, 2015 7:18 pm

Map JSON Array values to individual objects

In my app I make a call to web service and get JSON as a response. The structure of the JSON is following:
{
"ns1:AuthenticateResponse": {
"@xmlns:ns1": "authentication:xsd:1",
"ns1:Serial": "0012345.110000.101",
"ns1:Status": "Product is valid",
"ns1:MessageText": "Serial Number you entered for Product1 is verified",
"ns1:DetailedText": "For additional product information call customer service at 1 866 383 5205 ...",
"ns1:Attributes": {
"ns1:Attribute": [
{
"ns1:name": "Description",
"ns1:value": "Product1"
},
{
"ns1:name": "Name",
"ns1:value": "Product1 Name"
},...

The web service response is mapped like this (automatically):
Image

My questions is:
how do I map specific "ns1:Attributes" array element to 2 different text fields on the UI?
i.e. if I want one textbox to display the second element value and another textbox to display the first element value, how can I say something like ns1:Attribute where is an integer referring to an element order in the array?

thanks

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Map JSON Array values to individual objects

Hello,

  1. Please open screen and switch to the DATA tab, located just to the left of the Components palette.
  2. For “Add datasource,” select Service your_service_name. Click “Add.” The service has been added to the page.
  3. Click “Mapping” for Success event and map $ns1:Attributes to the screen.
  4. Expand $ns1:Attributes. You can map each field of each $ns1:Attributes item to any screen component.
  5. Click “Save and return”.
X Yz
Posts: 0
Joined: Tue Feb 10, 2015 7:18 pm

Map JSON Array values to individual objects

Evgene,
sorry that is not what I was asking, you described a simple 1:1 mapping use case.
My JSON has an array of objects returned and I need to map a specific array item to a storage variable.
"ns1:Attribute" is an array with objects that have identical structure like this:

"ns1:Attribute": [
{
"ns1:name": "Description",
"ns1:value": "some text"
},
{
"ns1:name": "Details",
"ns1:value": "some more details"
}]

My question was how do I map specific "ns1:value" to a textbox on the UI? i.e. how can I say something like this ns1:Attribute[2].ns1:value in the mapping screen?

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Map JSON Array values to individual objects

X Yz,

We fully understand you.

1) for instance place grid and 2 labels in it
2) map $ns1:Attribute to grid
3) map ns:name to label 1
4) map ns:value to label 2

After that appery.io will clone your grid and each new one will place new item from array

X Yz
Posts: 0
Joined: Tue Feb 10, 2015 7:18 pm

Map JSON Array values to individual objects

Hmmm, again your answer makes sense for a grid but I do not want to display a grid. As a matter of fact I do not want to map directly to a page, I want to map it to my Model.
Basically here is what I want to do step-by-step:

  1. I defined a model like this:

    Image

  2. I make a web service call on page1 and map the result to my model:
    Image

  3. On page2 (onLoad) I am mapping the Model (that was populated in step #2) to my objects on the page. This is where the problem is. I want to fetch the third array item from ns1:Attrribute array and associate that items "value" to the image object on the UI... but how do I specify that in the mapping? would it be via JS somehow?
    Image

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Map JSON Array values to individual objects

Hello X Yz,

Sorry for the delay, we are working on it and will get back to you with the update.

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Map JSON Array values to individual objects

X Yz,

You have the incorrect mapping
You have an array, it looks like that you want to take some value, but you try to take things in the right order
You should either:
1) select a single value
2) correctly map the array to the element, which can be cloned (grid, selectmenu, list, etc.)

Return to “Issues”