我正在使用com.amazonaws.util.json.JSONObject
在文档中它说
public String optString(String key)
Get an optional string associated with a key. It returns an empty string if there is no such key. If the value is not a string and is not null, then it is coverted to a string.
Parameters: key - A key string. Returns: A string which is the value.
我有一个像 {"time":1505900658464}
这样的 json 对象,当我使用 optstring 时,我希望它将这个 long 值转换为 string ,但它实际上返回“”(而不是转换为 string 的 long 值)。我错过了什么吗?
最佳答案
首先,如果没有可用的字符串值,optString()
方法应该返回空字符串:“”。
请参阅Documentation.
其次,对象{"time":1505900658464}
具有长值而不是字符串。您应该使用 optLong
来代替。请参阅Documentation .
此外,您可能需要阅读此 discussion ,并将时间从 Unix (这是您在示例中提供的格式)转换为 simpleDateFormat 请参阅 this.
关于java - optstring 未转换为字符串 [aws json 对象],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46320838/