javascript - 对象的JSON.stringify仅返回{}

标签 javascript json

我正在尝试将JavaScript对象转换为JSON。该对象格式正确,并且console.log(myObject)正确返回它。

但是,console.log(JSON.stringify(myObject));仅返回{}
我在这里想念什么?
编辑:有问题的对象:

 Object
  autor: "Administrador"
  descripcion: "At Google I/O 2015, everything we’ve seen and learned about is under the command of Sundar Pichai. In this exclusive interview, he walks us through his product vision.↵↵Subscribe: http://goo.gl/G5RXGs↵↵Check out our full video catalog: http://goo.gl/lfcGfq↵Visit our playlists: http://goo.gl/94XbKx↵Like The Verge on Facebook: http://goo.gl/2P1aGc↵Follow on Twitter: http://goo.gl/XTWX61↵Follow on Instagram: http://goo.gl/7ZeLvX↵Read More: http://www.theverge.com"
  titulo: "The future of Google with Sundar Pichai"
  url_imagen: "https://i.ytimg.com/vi/TguamcqrQjI/sddefault.jpg"
  url_video: "https://www.youtube.com/embed/TguamcqrQjI"
  __proto__: Object

编辑:这是我创建对象的方式:
var myObject = {};
    $http.get('apiCallToYoutubeIcantShareHereCauseItContainsAPrivateKey')
    .success(function(data) {

      myObject.titulo = data['items'][0]["snippet"]['title'];
      myObject.descripcion = data['items'][0]["snippet"]['description'];
      myObject.url_video ="https://www.youtube.com/embed/"+idYoutube;
      myObject.url_imagen = data['items'][0]["snippet"]['thumbnails']['standard']["url"];
      myObject.autor = 'Administrador';
    });

最佳答案

这是因为您的对象中有2个不属于该符号的分号;

您当前的代码:

var myObject = {
    "autor": "Administrador",
    "descripcion": "At Google I/O 2015, everything we’ve seen and learned about is under the command of Sundar Pichai.In this exclusive interview, he walks us through his product vision.Subscribe: goo.gl/G5RXGsFollow on Twitter: goo.gl/XTWX61↵Follow on Instagram: goo.gl/7ZeLvX ",
    "titulo": "The future of Google with Sundar Pichai",
    "url_imagen": "i.ytimg.com/vi/TguamcqrQjI/sddefault.jpg";, // <-- Semicolon that doesn't belong here
    "url_video": "youtube.com/embed/TguamcqrQjI"; // <-- Semicolon that doesn't belong here
};

跟随没有它们的对象:

JSFiddle:http://jsfiddle.net/zu2L3h5x/1/
var myObject = { 
    "autor": "Administrador",
    "descripcion": "At Google I/O 2015, everything we’ve seen and learned about is under the command of Sundar Pichai.In this exclusive interview, he walks us through his product vision.Subscribe: goo.gl/G5RXGsFollow on Twitter: goo.gl/XTWX61↵Follow on Instagram: goo.gl/7ZeLvX ",
    "titulo": "The future of Google with Sundar Pichai",
    "url_imagen": "i.ytimg.com/vi/TguamcqrQjI/sddefault.jpg",
    "url_video": "youtube.com/embed/TguamcqrQjI"
}; 

关于javascript - 对象的JSON.stringify仅返回{},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30777940/

相关文章:

javascript - 如何使用 Javascript 变量设置 jinja2 表达式?

javascript - 使用 jquery-localize 访问 javascript 函数中的本地化字符串

javascript - 在 AngularJS 中访问具有未知名称的嵌套 JSON 值

java - 将 URI 字符串解析为 JSON 对象

Android 数据库设计,使用 SQLite 或直接使用 mySQL 和 JSON

javascript - 将 json 文件附加到带有条件的 html

javascript - 多个无限循环

javascript - 按内容选择元素并删除其内容的第一个和最后一个字符

javascript - 枚举任意对象键 - Javascript

javascript - 类型 'Observable<void>' 不可分配给类型 'void | Action | Observable<Action>' 。添加效果时