我有JSON对象如下:
member = "{interests : [{interestKey:Dogs}, {interestKey:Cats}]}";
Run Code Online (Sandbox Code Playgroud)
在Java中,我想解析上面的json对象并将值存储在arraylist中.
我正在寻找一些代码,通过它我可以实现这一点.
JsonParser为 Spring Boot 应用程序获取已弃用的消息,
JsonObject jsonObject = new JsonParser().parse(result).getAsJsonObject();
Run Code Online (Sandbox Code Playgroud)
什么是替代方案?
我是来自Python背景的新Java程序员.我有收集/返回的天气数据作为带有嵌套键的JSON,我不明白在这种情况下如何拉出值.我确定之前已经问过这个问题,但是我发誓我用Google搜索了很多内容,我似乎无法找到答案.现在我正在使用json-simple,但我尝试切换到Jackson,但仍然无法弄清楚如何做到这一点.由于Jackson/Gson似乎是最常用的库,我很乐意看到使用其中一个库的示例.下面是数据的示例,后面是我到目前为止编写的代码.
{
"response": {
"features": {
"history": 1
}
},
"history": {
"date": {
"pretty": "April 13, 2010",
"year": "2010",
"mon": "04",
"mday": "13",
"hour": "12",
"min": "00",
"tzname": "America/Los_Angeles"
},
...
}
}
Run Code Online (Sandbox Code Playgroud)
主功能
public class Tester {
public static void main(String args[]) throws MalformedURLException, IOException, ParseException {
WundergroundAPI wu = new WundergroundAPI("*******60fedd095");
JSONObject json = wu.historical("San_Francisco", "CA", "20100413");
System.out.println(json.toString());
System.out.println();
//This only returns 1 level. Further .get() calls throw an exception
System.out.println(json.get("history"));
}
}
Run Code Online (Sandbox Code Playgroud)
函数'historical'调用另一个返回JSONObject的函数
public static JSONObject …Run Code Online (Sandbox Code Playgroud) 我正在尝试解析服务器的输出,如下所示:
{
"GetFolderFilesByZoneResult": [
{
"ID": 98748,
"CreatedBy": "",
"UpdatedBy": "none",
"CreatedDate": "\/Date(1308273033620+0100)\/",
"UpdatedDate": "\/Date(1308303003770+0100)\/",
"CommentCount": 0,
"Key": "",
"Enabled": true,
"MimeType": "video",
"Votes": 2,
"TotalRating": 0,
"AllowComments": true,
"ViewCount": 323,
"ReleaseDate": "\/Date(1308273000000+0100)\/",
"ExpireDate": "\/Date(4102444800000+0000)\/",
"Author": "",
"Size": 133799936,
"Tag1": "",
"Tag2": "",
"Tag3": "",
"RecycleBin": false
},
{
"ID": 99107,
"CreatedBy": "",
"UpdatedBy": "none",
"CreatedDate": "\/Date(1308583412520+0100)\/",
"UpdatedDate": "\/Date(1308583564007+0100)\/",
"CommentCount": 0,
"Key": "",
"Enabled": true,
"MimeType": "video",
"Votes": 0,
"TotalRating": 0,
"AllowComments": true,
"ViewCount": 33,
"ReleaseDate": "\/Date(1308583380000+0100)\/",
"ExpireDate": "\/Date(4102444800000+0000)\/",
"Author": …Run Code Online (Sandbox Code Playgroud) 我想在java中解析一个JSON文件,并从下面提到的文件中获取以下值:
{
"status": "OK",
"origin_addresses": [ "Vancouver, BC, Canada", "Seattle, État de Washington, États-Unis" ],
"destination_addresses": [ "San Francisco, Californie, États-Unis", "Victoria, BC, Canada" ],
"rows": [ {
"elements": [ {
"status": "OK",
"duration": {
"value": 340110,
"text": "3 jours 22 heures"
},
"distance": {
"value": 1734542,
"text": "1 735 km"
}
}, {
"status": "OK",
"duration": {
"value": 24487,
"text": "6 heures 48 minutes"
},
"distance": {
"value": 129324,
"text": "129 km"
}
} ]
}, {
"elements": [ …Run Code Online (Sandbox Code Playgroud) 我有一个类似的字符串 - {"state":1,"cmd":1},我需要将其与生成的输出进行比较,但在生成的输出中,顺序会不断变化,即有时它的{"state":1,"cmd":1}其他时间{"cmd":1,"state":1}.
目前我正在使用equals()方法进行比较,在这种情况下可以更好地验证两个字符串.我担心的是两个条目都存在于字符串中,顺序不是imp.
我在Android上搜索了很多关于JSON解析的内容,但还是不太相信.实际上有一个简短的想法,但关于JSON解析还不是很清楚.
如何在应用程序中实现JSON解析?
我刚刚发现杰克逊没有实现JSR-353并且我们已经设计了模块..所以我迫不及待地想要找到替代这个API来开始工作!:d
我搜索了一个实现标准但却找不到任何有趣结果的API,因为我们计划用标准编码并强制系统使用特定的实现(我正在拼命搜索的API)
json ×8
java ×7
parsing ×4
android ×3
gson ×2
jackson ×2
equals ×1
ip-address ×1
jsonobject ×1
jsonparser ×1
jsr-353 ×1
org.json ×1
spring ×1
spring-boot ×1
string ×1