0

Nothing displayed while parsing JSON object including unicode data in angular js.

app.controller('customersCtrl', function($scope, $http) {
    $http.get("http://www.hrjournalmyanmar.com/getarticle.cfm")
    .success(function (response) {$scope.names = response.mmjobs});
});



<md-list-item class="md-3-line" ng-repeat="item in names">
            <div class="md-list-item-text" layout="column">
                <h3>{{ item.title }}</h3>
            </div>
        <md-divider inset></md-divider>
</md-list-item>

Please help me how to solve it? Because I'm very new in angularJS.

2 Answers 2

1

try:

$http.get("http://www.hrjournalmyanmar.com/getarticle.cfm")
.then(function (response) {$scope.names = response.data.mmjobs;});

Deprecation Notice

The $http legacy promise methods success and error have been deprecated. Use the standard then method instead. If $httpProvider.useLegacyPromiseExtensions is set to false then these methods will throw $http/legacy error.

To fix the json content you can write your own response transformer and fix the " quotes and transform the content to unicode. http://plnkr.co/edit/1sZXmHZgRVUQNhOjluBU?p=preview

        $http.get("http://www.hrjournalmyanmar.com/getarticle.cfm", {
          'transformResponse': 
            function(data, headersGetter, status) {

              var out = '';
              angular.forEach(data, function(c) {
                var code = c.charCodeAt();
                if (code > 255) {
                  var n = Number(code).toString(16);
                  while (n.length < 4) {
                    n = '0' + n;
                  }
                  out += ('\\u' + n);
                } else {
                  out += c;
                }
              });
              out = out.replace('""', '"\\"');
              out = out.replace('" \\u', '\\" \\u');
              console.log(out);
              return angular.fromJson(out);
            }

          })
        .then(function(response) {
          $scope.names = response.data;
        });
Sign up to request clarification or add additional context in comments.

Comments

1

I think It is because http://www.hrjournalmyanmar.com/getarticle.cfm consist json data which is not parse-able(wrong).

test your json structure here:http://json.parser.online.fr/

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.