dictionary use

Former Member
Former Member
Hi all,
I have a dictionary as response from a makeJsonRequest.

The response is like this:
{elements=>[{param1=>aaa, param2=>aaa, param3=>12312300_1_0404039195575.png}, {param1=>bbb, param2=>bbb, param3=>12312300_1_0404039195576.png},
{param1=>ccc, param2=>ccc, param3=>12312300_1_0404039195577.png}, {param1=>ddd, param2=>ddd, param3=>12312300_1_0404039195578.png}]}


Please could you show me how to write a while loop to traverse it and get all his params inside each element?

Thanks in advance!
Stefano
  • It should not be difficult to have figured this out given the documentation for Array and Dictionary. The outermost object is a Dictionary, and you want the field named elements. The elements field is an Array, so you just iterate over that, and each of the objects in the Array are Dictionary with three fields param1, param2 and param3.

    I wouldn't personally use a while loop, but if you insist you could change the code below.

    function onResponse(code, data) {
    var elements = data.get("elements");

    for (var i = 0; i < elements.size(); ++i) {
    var element = elements;

    var p1 = element.get("param1");
    var p2 = element.get("param2");
    var p3 = element.get("param3");
    }
    }
    [/code]
  • Former Member
    Former Member over 9 years ago
    Hi TRAVIS,
    Thanks for your time.

    I wasn't aware of the size() method :) while on internet I saw some examples using length (non working esample) so I was confused.

    By the way, resolved this issue I discovered that the method makeImageRequest doesn't work, at least on current SDK 1.1.3.
    I found that un upcoming sdk 1.2 in September will fix it.