0
$scope.data = {
    "statusCode": 200,
    "message": "success",
    "result": {
        "data2": [
            {
                "viewTitle": "one",
                "viewType": 1,
                "viewData": "{\"data3\":{\"_id\":\"one\"," +
                "\"channelId\":\"0\",\"channelName\":\"animals\"," +
                "\"rate\":3.5,\"visited\":21,\"meta\":{\"currency\":\"t\"" +
                ",\"size\":\"5 mb\",\"updatedAt\":\"2 2 2016\"" +
                ",\"createdAt\":\"2 2 2016\",\"duration\":\"3 minutes \"}" +
                ",\"thumbnail\":\"127.0.0.1\"" +
                ",\"banner\":\"127.0.0.1\"" +
                ",\"trailerUrl\":\"\",\"url\":\"127.0.0.1\"" +
                ",\"desc\":\"my informations \"" +
                ",\"title\":\"my videos number 4\",\"packages\"" +
                ":[{\"_id\":\"1\",\"price\":500" +
                ",\"type\":\"purchase\"}],\"packageId\":\"2\"" +
                ",\"packagePrice\":500,\"userFavorite\":0,\"userRate\":0,\"locked\":1}}"
            }
        ]
    }
};`

I try to access for example chanelName or size please help to resolve.

1

3 Answers 3

0

first, turn the JSON string into an object via JSON.parse();
var data = JSON.parse(); //data is now the result of JSON.parse
and then access the property you want to use in $scope.data

Sign up to request clarification or add additional context in comments.

Comments

0

I have created a CodePen for your Problem: http://codepen.io/JohannesFerner/pen/PNmmBd/

You have JSON.parse(<escaped JSON property>) or angular.fromJson(<escaped JSON property>) (see the comment above) your escaped JSON.


Without further knowledge of your backend I would suggest that you do not deliver escaped JSON to the client.

Comments

0

First level objects can be accessed like this.

person.result.data2[0].viewTitle

JSON.parse is the easiest way here to disassemble the complex object. I have given my example below

http://jsfiddle.net/MisterFantastic/u8bhc1ds/1/

JSON.parse(person.result.data2[0].viewData)

For complex objects please refer this link. AngularJS format JSON string output

Comments

Your Answer

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