0

How do i extract 57 from this json [{"status":57}] in angular?

I have tried JSON.parse('{"status":57}').status but produces an error.

2
  • var_name[0].status Commented Jun 13, 2016 at 3:30
  • Please show more code context...where you get the json from and what you want to do with it. See minimal reproducible example. Also if something throws error... give full details of that error. Error messages are meaningful Commented Jun 13, 2016 at 3:30

2 Answers 2

1

[{"status":57}] is already an array / array of object

you just need to extract the value

data = [{"status":57}];
data[0].status
Sign up to request clarification or add additional context in comments.

3 Comments

well actually your first statement is incorrect because by definition json is a string. Saying it is already an array or object would be more accurate
@kiro112 the point is that JSON is string data-interchange format. When you use JSON.parse() you then take the JSON (string) and convert to javascript object. Many many people call an object a JSON object but that's not accurate and there is no such thing
i think i got it wrong too @charlietfl i always call it json / json object, thanks for pointing it out ! from now on ill call it array / object
0

Use angular.fromJson to deserialize JSON strings:

angular.fromJson([{"status":57}])[0].status;

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.