Reputation: 53
Here is the JSON response I am trying to parse and display the grid bank accounts in checkbox list. My question is how to parse the static value (287 and 288) in my case.
[{"id":"294","name_on_account":"9824873088 9824873088","balance":"10000.00","account_no":"8901"},{"id":"295","name_on_account":"9824873088 9824873088","balance":"10000.00","account_no":"8902"}]
Here is my code.
<div ng-controller="savebankaccounts">
<label ng-repeat="x in gridbank track by $index">
<input type="checkbox" value="{{x.id}}" ng-model="user.checked">{{x.account_no}}
</label>
</div>
Here is my scope variable in controller.
$scope.gridbank = localStorage.getItem("grid_bank_accounts");
I want to display the bank accounts listed in parameter grid_bank_accounts in checkbox list where user can check of them and save.
Cheers.
Upvotes: 0
Views: 56
Reputation: 43
you should do like below
$scope.gridbank = JSON.parse(localStorage.getItem("grid_bank_accounts"));
Upvotes: 1
Reputation: 346
{"status":1,"msg":"Verification successful.", "bank_accounts":["287","288"], "grid_bank_accounts": [{"287":{"id":"287","name_on_account":"1542365152","balance":"1000.00","account_no":"151515"}},{"288":{"id":"288","name_on_account":"115151456566262","balance":"1000000.00","account_no":"1514545"}}]}
var obj = JSON.parse(json);
if(obj.bank_accounts instanceof Array)
{
//do something
}
What is in alert is not a valid json (i was unable to parse it using JSON.parse(json) method function). i have modifed it and validated it. You can use typeof operator of javascript to check variable type type. Have a look at this for more. http://www.javascriptkit.com/javatutors/determinevar2.shtml
Upvotes: 1