0

I used the json example from this site (at the bottom) https://dev.twitter.com/rest/reference/get/statuses/home_timeline, copied it to a file on my local file system and then tried to get it via Angular's $http service like this:

First I defined a service:

Services.TwitterService = function ($http) {
  'use strict';

  var TwitterService = {
    getHome: function () {
      return $http.get("ws/home.json").then(function (response) {
        return response.data;
      });
    }
  };

  return TwitterService;
};

Then in my controller:

  $scope.twitter = TwitterService;

  TwitterService.getHome().then(function (data) {
    $scope.twitter.home = data;
  });

Unfortunately when I run the code, there seems to be a problem with a "/" character in the json because I get this exception:

SyntaxError: Unexpected token / at Object.parse (native)

Is Twitter's example json malformed or did I do something wrong? If the json file is invalid what can I do to fix it? Do I have to replace all occurrences of "/"?

1
  • 1
    Yes, JSON example is broken, quotes are not escapted properly in "source" properties. Commented Apr 11, 2015 at 21:28

1 Answer 1

1

Copy and paste the JSON in http://jsonlint.com/

It will validate the JSON code

The particular example you are mentioning seems not to be valid JSON.

Parse error on line 29:
..."source": "<a href="//realitytechnicians
-----------------------^
Expecting '}', ':', ',', ']'

It looks like there is a problem with quotes... you can fix it manually and go ahead, I don't think it is a problem you will see with real responses from Twitter API

Sign up to request clarification or add additional context in comments.

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.