E
E
Egor S2015-09-22 19:25:15
Angular
Egor S, 2015-09-22 19:25:15

Why does JSON come to the client as an array of individual characters?

JSON is sent from the server to the client, but the client receives this:


0: "["
1: "{"
2: """
3: "I"
4: "d"
5: """
6: ":"
7: "1"
8: ","
9: """
10: "T"
11: "i"
12: "t"
13: "l"
14: "e"
15: """
16: ":"
17: """
...
180: "}"
181: "]"
$promise: d
$resolved: true
__proto__: g

JS:
'use strict';

/* Controllers */

angular.module('ipsub.controllers', [])
  .controller('PreviewListController', ['$scope', '$rootScope', 'NewsFactory',
      function ($scope, $location, NewsFactory) {
          $scope.News = [];
          NewsFactory.PreviewList.get(function (data) {
              var a = data;
              debugger;
          });
    }])
  .controller('NewsEditCtrl', [function() {

  }])
  .controller('NewsDeleteCtrl', [function() {

  }]);

/* Services */

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

ipsubServices.factory('NewsFactory', function ($resource) {
    return {
        PreviewList: $resource('api/News/GetPreviewsList'),
        News: $resource('api/News/GetNewsDetail/:id', { id: '@id' })
};
});

C# server:
public class NewsController : ApiController
    {
        public NewsManager Nm = new NewsManager();
        /// <summary>
        /// Получение краткой информации о последнх 10 новостях  объявлениях
        /// </summary>
        /// <returns></returns>
        public string GetPreviewsList()
        {
            var result = new JavaScriptSerializer().Serialize(Nm.GetNewsList());
            return result;
        }
    }

On the server, normal JSON is stored in result. What could be the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
VanKrock, 2015-09-22
@VanKrock

Try using JsonSerializer instead of JavaScriptSerializer on the server

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question