I want to create a JSON string piece by piece and by using org.json.simple.JSONArray and org.json.simple.JSONObject. Here's the code.
1. JSONObject config = new JSONObject();
2. JSONArray urls = new JSONArray();
3. urls.add("https://www.test1.com/v1");
4. urls.add("https://www.test1.com/v2");
5. config.put("name", "name-test1");
6. config.put("sipUrls", sipUrls);
There is Eclipse warning for line 2 and 3:
And warning for line 5 and 6:
How can I get rid of these warnings?
PS
The problem addressed here is different from this How to correctly use HashMap? because there's no way to create a JSONArray<String> or JSONObject<String> . JSONArray and JSONObject are not parameterizable.
It appears that there's no way to parameterize org.json.simple.JSONArray and org.json.simple.JSONObject by its design. However, you can suppress these warnings by annotation:
@SuppressWarnings("unchecked")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.