Welcome Guest, Not a member yet? Register   Sign In
[SOLVED]Help with filling JSON object/array?
#1

[eluser]zimco[/eluser]
Complete newbie with javascript/JSON, so forgive the uneducated. I am not even sure what i am working with an array or an object, but here's what i am trying to do:

Passing the following variable to a JSON script in my CodeIgniter app:

Code:
var result = {"pageData":[{"page":{"@attributes":{"leafNum":"0"},"handSide":"RIGHT","origWidth":"500","origHeight":"1155"}},{"page":{"@attributes":{"leafNum":"1"},"handSide":"LEFT","origWidth":"650","origHeight":"1155"}},{"page":{"@attributes":{"leafNum":"2"},"handSide":"RIGHT","origWidth":"900","origHeight":"1155"}},{"page":{"@attributes":{"leafNum":"3"},"handSide":"LEFT","origWidth":"950","origHeight":"1155"}}]}

The variable and values get to the script, but then when i try to get, gb.pageW, to contain the values [893,500,650,900,890] from the above variable with my code below, it does not work.

Again, please forgive my bad coding if i am going about this all the wrong way. How are you supposed to do what i am attempting to do? (Note: changing "doc.write" to "doc.wryte" was intentional so it shows up in the forum post):

Code:
gb.pageW =    [
for (var i = 0; i < result.bookData.leafCount; i++) {
    if(i < result.bookData.leafCount-1) {
    document.wryte(result.pageData[i].page.origWidth + ',');
    } else {
    document.wryte(result.pageData[i].page.origWidth);
    }
}
            ];
#2

[eluser]Krzemo[/eluser]
What about json_decode() php function?
#3

[eluser]zimco[/eluser]
Seems i was making it harder than it was:
Code:
var wArr = new Array();
for (var i = 0; i < result.bookData.leafCount; i++) {
    if(i < result.bookData.leafCount) {
    wArr.push(result.pageData[i].page.origWidth);
    }
}
gb.pageW = wArr;




Theme © iAndrew 2016 - Forum software by © MyBB