2016-12-24 4 views
0

の取り扱い JSON次のように私はJSONレスポンスを持っている:テーブル内のJSONレスポンス

var res = { 
     "response": { 
     "status": { 
      "code": "0", 
      "message": "Success" 
     }, 
     "service": { 
      "servicetype": "3", 
      "functiontype": "3000", 
      "session_id": "966" 
     }, 
     "data": { 
      "profilesearchsnippet": [ 
      { 
       "profileInfo": { 
       "firstname": "Archita", 
       "lastname": "v", 
       "gender": "female", 
       "country": "India", 

       } 
      }, 

      { 
       "profileInfo": { 
       "firstname": "Archita", 
       "lastname": "V", 
       "gender": "female", 
       "country": "India", 

       } 
      }, 

      { 
       "profileInfo": { 
       "firstname": "Jayasree", 
       "lastname": "Salavadi", 
       "gender": "female", 
       "country": "Afghanistan", 

       } 
      }, 

      { 
       "profileInfo": { 
       "firstname": "Kalai", 
       "lastname": "Sundar", 
       "gender": "female", 
       "country": "India", 

       } 
      }, 

      { 
       "profileInfo": { 
       "firstname": "Singer", 
       "lastname": "sing", 
       "gender": "female", 
       "country": "Afghanistan", 

       } 
      } 

      ] 
     } 
     } 
    } 

は、私はすべてのファーストネームを取得したい、table.Iにおける国の状態市は、変数var SearchDataに割り当てるprofilesearchsnippet値を試してみましたが、フェッチしてみてくださいprofileinfoを使用してfirstnameを作成します。私はどこかに援助が必要なものを紛失している。

HTML:

<tr ng-repeat= "item in searchData"> 
     <td>{{searchData.profileInfo.firstname}}</td> 
     <td> {{searchData.profileInfo.country}}</td> 
     </tr> 

JS:

var searchData = res.response.data.profilesearchsnippet; 

答えて

1

1.あなたJSONがあるitemの内側に存在していると言うようあなたは...項目にデータをバインドする必要が間違っています有効ではありません。 ng-repeat使用{{item.profileInfo.firstname}}の代わり{{searchData.profileInfo.firstname}}インサイド

enter image description here

2.

の作業のデモ:

var myApp = angular.module('myApp',[]); 
 

 
myApp.controller('MyCtrl',function ($scope) { 
 
    var res = { 
 
\t "response": { 
 
\t \t "status": { 
 
\t \t \t "code": "0", 
 
\t \t \t "message": "Success" 
 
\t \t }, 
 
\t \t "service": { 
 
\t \t \t "servicetype": "3", 
 
\t \t \t "functiontype": "3000", 
 
\t \t \t "session_id": "966" 
 
\t \t }, 
 
\t \t "data": { 
 
\t \t \t "profilesearchsnippet": [{ 
 
\t \t \t \t \t "profileInfo": { 
 
\t \t \t \t \t \t "firstname": "Archita", 
 
\t \t \t \t \t \t "lastname": "v", 
 
\t \t \t \t \t \t "gender": "female", 
 
\t \t \t \t \t \t "country": "India" 
 
\t \t \t \t \t } 
 
\t \t \t \t }, 
 

 
\t \t \t \t { 
 
\t \t \t \t \t "profileInfo": { 
 
\t \t \t \t \t \t "firstname": "Archita", 
 
\t \t \t \t \t \t "lastname": "V", 
 
\t \t \t \t \t \t "gender": "female", 
 
\t \t \t \t \t \t "country": "India" 
 
\t \t \t \t \t } 
 
\t \t \t \t }, 
 

 
\t \t \t \t { 
 
\t \t \t \t \t "profileInfo": { 
 
\t \t \t \t \t \t "firstname": "Jayasree", 
 
\t \t \t \t \t \t "lastname": "Salavadi", 
 
\t \t \t \t \t \t "gender": "female", 
 
\t \t \t \t \t \t "country": "Afghanistan" 
 
\t \t \t \t \t } 
 
\t \t \t \t }, 
 

 
\t \t \t \t { 
 
\t \t \t \t \t "profileInfo": { 
 
\t \t \t \t \t \t "firstname": "Kalai", 
 
\t \t \t \t \t \t "lastname": "Sundar", 
 
\t \t \t \t \t \t "gender": "female", 
 
\t \t \t \t \t \t "country": "India" 
 
\t \t \t \t \t } 
 
\t \t \t \t }, 
 

 
\t \t \t \t { 
 
\t \t \t \t \t "profileInfo": { 
 
\t \t \t \t \t \t "firstname": "Singer", 
 
\t \t \t \t \t \t "lastname": "sing", 
 
\t \t \t \t \t \t "gender": "female", 
 
\t \t \t \t \t \t "country": "Afghanistan" 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 

 
\t \t \t ] 
 
\t \t } 
 
\t } 
 
}; 
 

 
$scope.searchData = res.response.data.profilesearchsnippet; 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="MyCtrl"> 
 
    <table> 
 
    <tr ng-repeat= "item in searchData"> 
 
     <td>{{item.profileInfo.firstname}}</td> 
 
     <td> {{item.profileInfo.country}}</td> 
 
     </tr> 
 
    </table> 
 
</div>

1

あなたのtdタグでitemないsearchDataを参照する必要があります。

<tr ng-repeat="item in searchData"> 
    <td> {{item.profileInfo.firstname}} </td> 
    <td> {{item.profileInfo.country}} </td> 
    </tr> 
+0

それが機能していません。取得される値はありません –

2

JSON形式が正しくありません。あなたのコードには特別なcommas(,)がいくつかあります。以下は有効なJSONです。

var res = { 
    "response": { 
     "status": { 
      "code": "0", 
      "message": "Success" 
     }, 
     "service": { 
      "servicetype": "3", 
      "functiontype": "3000", 
      "session_id": "966" 
     }, 
     "data": { 
      "profilesearchsnippet": [{ 
        "profileInfo": { 
         "firstname": "Archita", 
         "lastname": "v", 
         "gender": "female", 
         "country": "India" 

        } 
       }, 

       { 
        "profileInfo": { 
         "firstname": "Archita", 
         "lastname": "V", 
         "gender": "female", 
         "country": "India" 

        } 
       }, 

       { 
        "profileInfo": { 
         "firstname": "Jayasree", 
         "lastname": "Salavadi", 
         "gender": "female", 
         "country": "Afghanistan" 

        } 
       }, 

       { 
        "profileInfo": { 
         "firstname": "Kalai", 
         "lastname": "Sundar", 
         "gender": "female", 
         "country": "India" 

        } 
       }, 

       { 
        "profileInfo": { 
         "firstname": "Singer", 
         "lastname": "sing", 
         "gender": "female", 
         "country": "Afghanistan" 

        } 
       } 

      ] 
     } 
    } 
} 

はこれを行うHTMLで今 searchData

profilesearchsnippetを保存することを忘れないでください。

<tr ng-repeat="item in searchData"> 
    <td> {{item.profileInfo.firstname}} </td> 
    <td> {{item.profileInfo.country}} </td> 
    </tr> 
0

まず、あなたのJSは間違っている...

あなたは、コントローラ内のスコープを使用している場合は...その後、ないにフライVAR ... にしている場合、scopeに値をバインドしますその後、this

this.searchData = res.response.data.profilesearchsnippet; 

<.... ng-controller="myController as ctrl"> 
{{ctrl.searchData }} 
</...> 

にデータをバインドする、とあなたは、コントローラを使用するそう

$scope.searchData = res.response.data.profilesearchsnippet; 

<.... ng-controller="myController"> 
{{searchData }} 
</...> 

あなたはこれを修正したら...あなたもマイクが言ったところ...あなたはsearchData