0

I have a JSON object Like this-

[
{
    "user": "A220",
    "shorttext": "shanghai",
    "reportedBy": "S,A",
    "questions": "

[{\"question\":\"Q1\",\"is_mand\":\"0\",\"type\":\"text\",\"answer\":\"w\",\"ansYesOrNo\":false,\"ansDetails\":\"\"},{\"question\":\"Q2\",\"is_mand\":\"0\",\"type\":\"text\",\"answer\":\"ed\",\"ansYesOrNo\":false,\"ansDetails\":\"\"}]",
        "notifno": "20143995",
        "error": "",
        "createdOn": "2015-09-09 13:08:36",
        "Id": 0,
        "$$hashKey": "object:89"
    }
]

I need to access the 1st question of questions.Please i am not able to access it like this alert(obj.questions[0].question); Here is a jsFiddle Link-LINK to Fiddle

3
  • 1
    It is in an array, use obj[0].questions[0].question after you fix you questions array - remove backslashes. Use this site for your json validation. Commented Sep 10, 2015 at 9:10
  • jsfiddle: jsfiddle.net/w02ck9uw/2 use JSON.parse Commented Sep 10, 2015 at 9:14
  • There is no such thing as a JSON object. JSON is a text representation of a JavaScript object. What you have is a JS object with whats seems to be a JSON string as the value for the questions property, which seems very messed up. Usually it's full on one or the other Commented Sep 10, 2015 at 9:15

2 Answers 2

1

The main problem is that the questions array inside the object, It is not an array. Is a Array convert to string, you must parse the questions to get the respective Json object with the data.

Here is your fiddle updated: http://jsfiddle.net/marduke182/w02ck9uw/1/

And the part of code important:

var questonObj = JSON.parse($scope.a[0].questions);
Sign up to request clarification or add additional context in comments.

Comments

0

Use fromJson method this way:

angular.fromJson(a[0].questions)[0].question

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.