How to read JSON parsed from text in angular view


I need to read the following JSON text from my fetched database, below was my sample code:


The real data in qst_cnt_options was:

[{left:'Benda Hidup',right:'Benda Mati'}] //Fetched from database and as text

When I tried to read back, the output was only [. How to solve this problem?

Since the fetched value from the database is simple text, use JSON.parse to parse into a json object and retrieve it.

[{left:'Benda Hidup',right:'Benda Mati'}] this is a string, so returning [ as first value.

Method1: just return the JSON parsed value from the contrller,

In your controller:

    $scope.qst_cnt_options =  $scope.questionData1[0].JSON.parse(qst_cnt_options)

In your view:



    $scope.qst_cnt_options =  questionData1[0].JSON.parse(qst_cnt_options)

    $scope.parJson = function (json) {
            return JSON.parse(json)[0];