如何解析angularjs应用程序中的Drupal JSON数据

时间:2016-05-05 06:21:12

标签: javascript angularjs json drupal drupal-7

我从Drupal rest api获得了以下JSON resposne。如何在我的移动应用程序中解析它 - AngularJs http服务?



pthread_cond_wait to wait on the condition
pthread_cond_signal  to signal one thread of the waiters
pthread_cond_broadcast  to signal all threads that are waiting




1 个答案:

答案 0 :(得分:1)

例如

<强>控制器

   Cache-Control →no-store, no-cache, must-revalidate, post-check=0, pre-   
   check=0
   Connection →Keep-Alive
   Content-Length →0
   Content-Type →application/json
   Date →Thu, 05 May 2016 06:49:28 GMT
   Expires →Thu, 19 Nov 1981 08:52:00 GMT
   Keep-Alive →timeout=5, max=100
   Pragma →no-cache
   Server →Apache/2.4.18 (Unix) LibreSSL/2.2.6 PHP/5.5.31
   X-Powered-By →PHP/5.5.31

查看

app.controller('MyCtrlr', function ($scope, $http) {


                      $http.get("YOUR_DRUPAL_API").success(function(response){

                         //Store your JSON Response
                                 $scope.jsonResp = [  
                                                   {  
                                                      "nid":"2",
                                                      "title":"<a href=\"/sell/test-event-1\">Test Event 1</a>",
                                                      "field_event_list":"List of Test Event 1 . List of Test Event 1 . List of Test Event 1 . List of Test Event 1 . List of Test Event 1 . List of Test Event 1 . Summery of Test Event 1 . List of Test Event 1 . List of Test Event 1 . List of Test Event 1 . List of Test Event 1 . ",
                                                      "event_date":"<div class=\"date-display-range\"><span class=\"date-display-start\" property=\"dc:date\" datatype=\"xsd:dateTime\" content=\"2016-05-20T00:00:00+05:30\">Friday, May 20, 2016</span> to <span class=\"date-display-end\" property=\"dc:date\" datatype=\"xsd:dateTime\" content=\"2016-05-31T00:00:00+05:30\">Tuesday, May 31, 2016</span></div>"
                                                   }
                                                ];

                       });

 });

//AngularJS filter to strip HTML tags from your JSON properties

app.filter('getPlaintext', function() {
    return function(text) {
      return  text ? String(text).replace(/<[^>]+>/gm, '') : '';
   }
  });

参见 Fiddle