简体   繁体   中英

I can get the whole json data but i can't get a specific value from it

I'm building a android app by using ionic framework. I need to get a specific value from a json file which is on web but although i can get the whole data i can't get a specific value.

my controller in app.js :

.controller("detail", ["$scope", "$http", "$stateParams", 

function($scope, $http, $stateParams){
  $http.get("http://example.com/app/detay.php?id=" + $stateParams.id, config)
  .success(function(response){
    $scope.data = response;
  })

  .error(function(response, status, headers) {
    $scope.data = response || "Request failed" + status;
 });
}]);

my html :

<div ng-controller="detail">

  <div class="overview">
    {{data}}
  </div>

</div>

i can pull {{data}}

but i cant pull {{data.description}}

sample json :

[{"id":"907","name":"U\u00e7urtma","description":"<p><strong>Kahve fal\u0131nda u\u00e7urtma g\u00f6rmek<\/strong>, sevdi\u011finiz ve de\u011fer verdi\u011finiz dostlar\u0131n\u0131zdan sizi uzakla\u015ft\u0131rmak isteyen birinin oldu\u011funa i\u015faret eder. Okul ve hayat\u0131n\u0131z e\u011fer yolunda ise bu rahatl\u0131\u011fa ve \u00f6zg\u00fcvene aldanmay\u0131p \u00e7al\u0131\u015fma temponuzda herhangi bir azaltma yapmayarak \u00e7al\u0131\u015fmalar\u0131n\u0131za devam etmelisiniz aksi taktirde geri d\u00f6n\u00fc\u015f\u00fc olmayan \u00fcmitsizlik i\u00e7eren bir yola girebilirsiniz.<\/p>\n<p>Kahve fal\u0131nda u\u00e7urtma g\u00f6rmek ne anlama gelir sorusuna verilebilecek cevaplardan bir tanesi ; uzak bir yerden haber alacaks\u0131n\u0131z ve haks\u0131z kazan\u00e7 ile b\u00fcy\u00fck bir mevki veya i\u015f sahibi olaca\u011f\u0131n\u0131za haber verir.<\/p>\n<p><strong>U\u00e7urtma<\/strong> g\u00f6rmek, akla gelmeyen s\u0131rad\u0131\u015f\u0131 fikirlere de sembol olabilir. E\u011fer u\u00e7urtman\u0131z yere d\u00fc\u015fm\u00fc\u015f bir durumdaysa yalan haberler alaca\u011f\u0131n\u0131za i\u015farettir.<\/p>\n<p><strong>U\u00e7urtma u\u00e7urtmak<\/strong> vaktinizi bo\u015fa harcad\u0131\u011f\u0131n\u0131za, sihir ve b\u00fcy\u00fclerden uzak durman\u0131za aksi halde b\u00fcy\u00fck zararlar g\u00f6rece\u011finize i\u015farettir. E\u011fer sizi bo\u015f yere u\u011fra\u015ft\u0131ran bu gereksiz \u015feylerden uzak durursan\u0131z mevki ve makam\u0131n\u0131z y\u00fckselerek insanlar aras\u0131nda daha sayg\u0131n bir ki\u015fi olabilirsiniz.<\/p>\n<p><strong>U\u00e7urtma g\u00f6rmek<\/strong> ba\u015far\u0131lar\u0131n\u0131z\u0131 b\u00fcy\u00fck bir kibirle etraf\u0131n\u0131zdakilere s\u00f6ylerek d\u00fc\u015fman kazanman\u0131za ve zarar g\u00f6rmenize neden olabilir.<\/p>\n"}]

That's because your data is array. Not a object.

[{"id":"907","name":"U\u00e7urtma","description":"<p><strong>Kahve fal\u0131nda u\u00e7urtma g\u00f6rmek<\/strong>, sevdi\u011finiz ve de\u011fer verdi\u011finiz dostlar\u0131n\u0131zdan sizi uzakla\u015ft\u0131rmak isteyen birinin oldu\u011funa i\u015faret eder. Okul ve hayat\u0131n\u0131z e\u011fer yolunda ise bu rahatl\u0131\u011fa ve \u00f6zg\u00fcvene aldanmay\u0131p \u00e7al\u0131\u015fma temponuzda herhangi bir azaltma yapmayarak \u00e7al\u0131\u015fmalar\u0131n\u0131za devam etmelisiniz aksi taktirde geri d\u00f6n\u00fc\u015f\u00fc olmayan \u00fcmitsizlik i\u00e7eren bir yola girebilirsiniz.<\/p>\n<p>Kahve fal\u0131nda u\u00e7urtma g\u00f6rmek ne anlama gelir sorusuna verilebilecek cevaplardan bir tanesi ; uzak bir yerden haber alacaks\u0131n\u0131z ve haks\u0131z kazan\u00e7 ile b\u00fcy\u00fck bir mevki veya i\u015f sahibi olaca\u011f\u0131n\u0131za haber verir.<\/p>\n<p><strong>U\u00e7urtma<\/strong> g\u00f6rmek, akla gelmeyen s\u0131rad\u0131\u015f\u0131 fikirlere de sembol olabilir. E\u011fer u\u00e7urtman\u0131z yere d\u00fc\u015fm\u00fc\u015f bir durumdaysa yalan haberler alaca\u011f\u0131n\u0131za i\u015farettir.<\/p>\n<p><strong>U\u00e7urtma u\u00e7urtmak<\/strong> vaktinizi bo\u015fa harcad\u0131\u011f\u0131n\u0131za, sihir ve b\u00fcy\u00fclerden uzak durman\u0131za aksi halde b\u00fcy\u00fck zararlar g\u00f6rece\u011finize i\u015farettir. E\u011fer sizi bo\u015f yere u\u011fra\u015ft\u0131ran bu gereksiz \u015feylerden uzak durursan\u0131z mevki ve makam\u0131n\u0131z y\u00fckselerek insanlar aras\u0131nda daha sayg\u0131n bir ki\u015fi olabilirsiniz.<\/p>\n<p><strong>U\u00e7urtma g\u00f6rmek<\/strong> ba\u015far\u0131lar\u0131n\u0131z\u0131 b\u00fcy\u00fck bir kibirle etraf\u0131n\u0131zdakilere s\u00f6ylerek d\u00fc\u015fman kazanman\u0131za ve zarar g\u00f6rmenize neden olabilir.<\/p>\n"}]

Try this {{data[0].description}}

Use {{data[0].description}} instead of {{data.description}} . Your json data is an array so you may have to iterate through it using ng-repeat .

Something like this:

<div ng-controller="detail">

  <div ng-repeat="d in data" class="overview">
    {{d.description}}
  </div>

</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM