0

I am getting a JSON in response from server:

{
    "width": "765",
    "height": "990",
    "srcPath": "http://192.168.5.13:8888/ebook/user_content/_ADMIN_/_MERGED_/1273.pdf",
    "coverPage": "",
    "documents": [
        {
            "index": "1",
            "text": "Archiving Microsoft® Office SharePoint® Server 2007 Data with the Hitachi Content Archive Platform and Hitachi Data Discovery for Microsoft SharePoint",
            "type": "doc",
            "id": "HDS_054227~201106290029",
            "children": [
                {
                    "text": "Page 1",
                    "leaf": "true",
                    "pageLocation": "http://192.168.5.13:8888/ebook/user_content/_ADMIN_/_IMAGES_/HDS_054227~201106290029/image_1.png"
                },
                {
                    "text": "Page 2",
                    "leaf": "true",
                    "pageLocation": "http://192.168.5.13:8888/ebook/user_content/_ADMIN_/_IMAGES_/HDS_054227~201106290029/image_2.png"
                }               

            ]
        },
        {
            "index": "11",
            "text": "Brocade FCoE Enabling Server I/O Consolidation",
            "type": "doc",
            "id": "HDS_053732~201105261741",
            "children": [
                {
                    "text": "Page 1",
                    "leaf": "true",
                    "pageLocation": "http://192.168.5.13:8888/ebook/user_content/_ADMIN_/_IMAGES_/HDS_053732~201105261741/image_1.png"
                },
                {
                    "text": "Page 2",
                    "leaf": "true",
                    "pageLocation": "http://192.168.5.13:8888/ebook/user_content/_ADMIN_/_IMAGES_/HDS_053732~201105261741/image_2.png"
                }
                     ]
        }
    ]
}

And I want to get pagelocation of the children.

Can anyone tell me how to do this?

Hi i also want to get indexes from this and then want to get pagelocations of that particular children. Can you tell me how would i do that?

And also when i when i am getting indexes array it is returning me ,, only and not the index nos. I am using following code for that :

  indexes=response.documents.map(function(e){ return e.children.index; }) 

Thanks & Regards

2 Answers 2

2

If you're interested in simply retrieving all the page locations, you can do it using filter:

var locations = [];
json.documents.forEach(function(e,i) {
    e.children.forEach(function(e2,i2) {
        locations.push(e2.pageLocation);
    )}
});
// returns flat array like [item1,item2,item3,item4]

You can get an array of arrays using map:

var locations = [];
var locations = json.documents.map(function(e) {
    return e.children.map(function(e2) {
        return e2.pageLocation;
    });
});

// returns 2-dimensional array like [[item1,item2],[item1,item2]]
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @dbaseman i also want to get indexes from this and then want to get pagelocations of that particular children. Can you tell me how would i do that? And also when i when i am getting indexes array it is returning me ,, only and not the index nos. I am using following code for that : indexes=response.documents.map(function(e){ return e.children.index; })
0

Your json response is an appropriate javascript object So you can access all elements of the object like you do as in back end. here, you have an array of object of the type documents and each document object has array of objects of the type children. so syntax would be

myjson.documents[0].children[0].pagelocation 

( = http://192.168.5.13:8888/ebook/user_content/_ADMIN_/_IMAGES_/HDS_054227~201106290029/image_1.png)

will give you the very first page location.. and so on

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.