Javadoc说:
public interface JsonObjectextends JsonStructure, Map<String,JsonValue>
因此,JSONObject是一个Map,其键的类型为
String,其值的类型为
JSONValue。
和的javadoc
Map<K,V>.keySet()说:
Set<K> keySet()Returns a Set view of the keys contained in this map
因此,
JSONObject.keySet()返回的是一个
Set<String>(这很合逻辑,因为JSON对象的键是字符串)。
因此,您所需要做的就是:
Set<String> keys = posts.keySet();



