我正在使用java并且我导入了
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
假设我有“freeBaggageAvailable”
"freeBaggageAvailable" : [
{
"Y" : [{
"*" : [{"num":1,"weight": 23,"price": 0}],
"mc" : [{"num:":1,"weight" : 23,"price": 0}, {"num":2, "weight": 23,"price": 0}],
"mp" : [{"num:":1,"weight" : 23,"price": 0}, {"num":2, "weight": 23,"price": 0}],
"mmc" :[{"num:":1,"weight" : 23,"price": 0}, {"num":2, "weight": 32,"price": 0}]
}],
"C" : [{
"*" : [{"num":1,"weight":32 ,"price": 0},{"num":1,"weight":32 ,"price": 0}],
"mc" : [{"num:":1,"weight" : 32,"price": 0}, {"num":2, "weight": 32,"price": 0},{"num":3,"weight":32 ,"price": 0}],
"mp" : [{"num:":1,"weight" : 32,"price": 0}, {"num":2, "weight": 32,"price": 0},{"num":3,"weight":32 ,"price": 0}],
"mmc" :[{"num:":1,"weight" : 23,"price": 0}, {"num":2, "weight": 32,"price": 0}]
}],
"F" : [{
"*" : [{"num":1,"weight":32 ,"price": 0},{"num":1,"weight":32 ,"price": 0}],
"mc" : [{"num:":1,"weight" : 32,"price": 0}, {"num":2, "weight": 32,"price": 0},{"num":3,"weight":32 ,"price": 0},{"num":4,"weight":32 ,"price": 0}],
"mp" : [{"num:":1,"weight" : 32,"price": 0}, {"num":2, "weight": 32,"price": 0},{"num":3,"weight":32 ,"price": 0},{"num":4,"weight":32 ,"price": 0}],
"mmc" :[{"num:":1,"weight" : 23,"price": 0}, {"num":2, "weight": 32,"price": 0},{"num":4,"weight":32 ,"price": 0}]
}]}
],
如果我想访问数据“Y”->“mc”->“num”
如何从 JsonObject 访问它
File file = new File(classLoader.getResource("files/BaggageInfoPolicy.json").getFile());
Object obj = parser.parse(new FileReader(file));
JSONObject jsonObject = (JSONObject) obj;