0

I'm having trouble getting to object in json file.

I'm using

 .controller("ListController", ["$scope", "$http", function($scope, $http){
        $http.get('../scripts/bbtv.json').success(function(data) {
            $scope.artists = data;               
        });
    }])

The data gets in the variable, but I can't access any object of it. Here is part of the json file. For example how to print out {{programmeField.titleField.valueField}} ?

{
"channelField": [
{
  "displaynameField": [
    {
      "valueField": "bTV"
    }
  ],
  "idField": "BBTV"
}
],
"programmeField": [
{
  "titleField": [
    {
      "langField": "BULG",
      "valueField": "Тази сутрин"
    }
  ],
  "subtitleField": [],
  "creditsField": {
    "moderatorField": [
      "Антон Хекимян"
    ]
  },
  "categoryField": [
    {
      "langField": "BULG",
      "valueField": "Информационно предаване"
    },
    {
      "langField": "BULG",
      "valueField": "Сутрешен блок"
    }
  ],
  "languageField": {
    "valueField": "BULG"
  },
  "lengthField": {
    "unitsField": 1,
    "valueField": "180"
  },
  "videoField": {
    "presentField": "yes",
    "colourField": "yes",
    "aspectField": "4:3",
    "qualityField": "800x600"
  },
  "audioField": {
    "presentField": "yes",
    "stereoField": "no",
    "dolbyDigitalField": "no",
    "dolbySurroundField": "no"
  },
  "startField": "20151216063000 +0200",
  "stopField": "20151216093000 +0200",
  "channelField": "BBTV",
  "clumpidxField": "0/1",
  "_photos": [
    {
      "_id": "5f38a2ab2fedd6b0e48da60b833bb4ddb69d3a1c",
      "_url": "***.jpg",
      "_type": "Letterbox"
    }
  ],
  "_deleted": false,
  "_id": "189397717",
  "_contentId": 45207610,
  "_broadcastdate": "20151216"
}
}
3
  • Are you looking for JSON.parse(data) ? Commented Dec 16, 2015 at 14:20
  • 1
    I got error when i validated your JSON. Check if your JSON is formed properly. Commented Dec 16, 2015 at 14:25
  • JSON is valid, I just cut out part of it for the example :) Commented Dec 16, 2015 at 14:58

2 Answers 2

2

JSON is a transport format. Once it's decoded, it's a native data structure, like any other structure. Since you're in JS, use JS conventions, and follow the bracketing/bracing. Note the labelling on the objects/arrays below:

data = { "channelField": [
       a                 b
            { "displaynameField": [
            c                     d
                { "valueField": "bTV"
                e
                }
            ],
              "idField": "BBTV"

data.channelField[0].displaynameField[0].valueField -> "bTV"
    a             b c                 d e
Sign up to request clarification or add additional context in comments.

1 Comment

Can you help me to loop through and print out all valueField from the json? I am trying to do it with "ng-repeat", but without success.
1

Since your "programmeField" and "titleField" are array, use programmeField[0].titleField[0].valueField

In future you can copy your json to http://jsonviewer.stack.hu/ and the click on the Viewer tab.

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.