2

我可以不 JSON.stringify() ee.List() 的输出吗?

var dates = ee.List(imageCollection.get('date_range'));
print('type: ', typeof(dates));
print('JSON.stringify: ', JSON.stringify(dates));

print('Date zero: ', dates.get(0));
print('type: ', typeof(dates.get(0)))
print('JSON.stringify: ', JSON.stringify(dates.get(0)))

控制台说:

type: 
object
JSON.stringify: 
{} 

Date zero: 
1365638400000
type: 
object
JSON.stringify: 
{}  

我的最终游戏是将 dates.get(0) 解释为整数....

4

1 回答 1

2

这些是服务器对象。您必须请求它们的值(使用同步getInfo()或异步evaluate())与客户端函数混合和匹配,例如JSON.stringify()

var dates = ee.List(imageCollection.get('date_range'));
print('type: ', typeof(dates));
print('JSON.stringify: ', JSON.stringify(dates.getInfo()));

print('Date zero: ', dates.get(0));
print('type: ', typeof(dates.get(0)))
print('JSON.stringify: ', JSON.stringify(dates.get(0).getInfo()))

请注意,此时无需对任何内容进行字符串化。即dates.get(0).getInfo()是一个Number

print('A number: ', Number(dates.get(0).getInfo()))
于 2018-05-07T18:31:50.037 回答