MikeOry
Posts: 0
Joined: Tue Feb 28, 2012 11:26 pm

Parsing JSON data with multiple fields in each row

I have some JSON returned from REST that looks like this:

{
"query": {
"count": 8,
"created": "2012-02-28T23:22:20Z",
"lang": "en-US",
"results": {
"tr": [
{
"td": [
{
"align": "right",
"p": "(9)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$1 - $2"
},
{
"style": "padding-left: 25px;",
"p": "NLHOLDEM"
}
]
},
{
"td": [
{
"align": "right",
"p": "(3)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$2 - $4"
},
{
"style": "padding-left: 25px;",
"p": "HOLDEM"
}
]
},

etc

so there's an array of TRs and each contain an array of TDs. inside the TDs there are three different values for "p" "9", "$1-$2" and "NLHOLDEM". Then there is another TD with three "p"s etc.

I want to map each of the P values to a field in a row

so my table would look like
9 $1-$2 NLHOLDEM
etc
etc

I see how to build the grid and put three labels in it, but I can't figure out how to map this.

thanks in advance

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Parsing JSON data with multiple fields in each row

Could you post the entire JSON response or share the service URL (if public)?

MikeOry
Posts: 0
Joined: Tue Feb 28, 2012 11:26 pm

Parsing JSON data with multiple fields in each row

{
"query": {
"count": 8,
"created": "2012-02-28T23:22:20Z",
"lang": "en-US",
"results": {
"tr": [
{
"td": [
{
"align": "right",
"p": "(9)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$1 - $2"
},
{
"style": "padding-left: 25px;",
"p": "NLHOLDEM"
}
]
},
{
"td": [
{
"align": "right",
"p": "(3)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$2 - $4"
},
{
"style": "padding-left: 25px;",
"p": "HOLDEM"
}
]
},
{
"td": [
{
"align": "right",
"p": "(4)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$2 - $5"
},
{
"style": "padding-left: 25px;",
"p": "NLHOLDEM"
}
]
},
{
"td": [
{
"align": "right",
"p": "(1)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$5 - $10"
},
{
"style": "padding-left: 25px;",
"p": "NL 9MAX"
}
]
},
{
"td": [
{
"align": "right",
"p": "(1)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$10 - $20"
},
{
"style": "padding-left: 25px;",
"p": "HOLDEM"
}
]
},
{
"td": [
{
"align": "right",
"p": "(1)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$10 - $25"
},
{
"style": "padding-left: 25px;",
"p": "NL 9MAX"
}
]
},
{
"td": [
{
"align": "right",
"p": "(1)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$20 - $40"
},
{
"style": "padding-left: 25px;",
"p": "HOLDEM"
}
]
},
{
"td": [
{
"align": "right",
"p": "(1)"
},
{
"align": "center",
"style": "padding-left: 15px",
"p": "$40 - $80"
},
{
"style": "padding-left: 25px;",
"p": "MIXED"
}
]
}
]
}
}
}

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Parsing JSON data with multiple fields in each row

I used Echo service with JSON you provided. This is how the response is defined:

Image

The td[0].p, td[1].p and td[2].p -- I defined manually. This is to make it possible to display values in the same row. You can also just map to td.p, but then each value would be displayed in separate row.

This is data binding to the UI:
Image

Screen:
Image

You can try the app here:
http://tiggzi.com/preview/28618/

MikeOry
Posts: 0
Joined: Tue Feb 28, 2012 11:26 pm

Parsing JSON data with multiple fields in each row

amazing! thanks so much Max. I knew it was something with the td[0] array, but could not figure out the syntax! really appreciate the quick response.

Return to “Issues”