gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:35:19 25 4
gpt4 key购买 nike

我正在尝试将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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com