JSONObjectのデータを取得するためにJSONObjectを解析しようとしています。JSONObjectからJSONObjectクラスへのキャスト例外
しかし、問題は、JSONParserはorg.json.simple.JSONParserのクラスであり、JSONObjectはorg.json.JSONObjectにあります。
クラスを避けるためにorg.json内にパーサーが見つかりませんキャストの例外です!
他の方法でソートしてもらえますか?
まったく間違った方向に行っていますか?
私のJSONが見えるお勧めしてください:
{
"dataIntents": [
{
"intent": "muster.policy.daily",
"expr": "Am I supposed to register my attendance daily?"
},
{
"intent": "leave.probation",
"expr": "An employee is eligible for how many leaves in 1st year ??"
},
{
"intent": " leave.resigned ",
"expr": "Are resigned employees eligible for pro rata leave credit"
},
{
"intent": " muster.deadline.submission ",
"expr": "By when should I get my pending leave/Emuster applications
approved?"
}
]
}
私のメインクラス:
public class DLMain {
public static void main(String[] args) {
try {
JSONParser parser = new JSONParser();
Object obj =
parser.parse(newFileReader("/home/cmss/Downloads/data.json"));
org.json.JSONObject dataObject = (org.json.JSONObject)obj;
System.out.println(dataObject);
org.json.JSONArray getArray =
dataObject.getJSONArray("dataIntents");
for (int i = 0; i < getArray.length(); i++) {
org.json.JSONObject objects = getArray.getJSONObject(i);
String a = objects.getString("expr");
}
System.out.println();
} catch (Exception e) {
System.out.println(e);
}
}
}
私はJSONObjectまたはStringで私の "式expr" キーのすべての値を求めています。
ヘルプは事前に感謝しています:)
org.simple.json.JSONArrayを使用すると、dataObject.getJSONArray( "dataIntents"にエラーが発生しています)の場合、 'org.json.simple.JSONObject'と' org.json.simple.JSONArray' – SpaceBison
@SpaceBisonを試してみてください。 "); – shubham
'org.json.simple.JSONObject'は、別のライブラリからのものであるため、' org.json.JSONObject'とは異なるインターフェースを持っています。詳細については、docsを参照してください:http://alex-public-doc.s3.amazonaws.com/json_simple-1.1/index.html – SpaceBison