次のような大きなJSONファイルがあります。Java WebプログラムのデータベースへのJSONファイルの解析
[{"id":0,"name":"Mrs. Tess Goyette","priceRange":{"min":86,"max":87},"requirements":["close to transport","internet","bath","gym"]},..
賢明のように、999アイテムがあります。私はこのデータをMySQLデータベースに送りたいと思っています。また いくつかの取引をします。このような40のホテル名と宿泊施設というデータを持つファイルがもう1つあります。
私はこのファイルをjavaで解析することができません。誰でも助けることができますか? 1つのJSONオブジェクトと配列を作成しようとしましたが、失敗しました。 enter code here
ご迷惑をおかけして申し訳ございません。
はい私はこのようなコードを作成しようとしています。
public static void main(String[] args) {
JSONParser parser = new JSONParser();
try {
JSONParser parser = new JSONParser();
InputStream is = hoteldemo.class.getResourceAsStream("accommodation.json");
String jsonTxt = IOUtils.toString(is);
JSON json = JSONSerializer.toJSON(jsonTxt);
JSONObject json1 = (JSONObject)JSONSerializer.toJSON(jsonTxt);
JSONObject json2= json1.getJSONObject("menu");
double id = json2.getDouble("id");
String name = json2.getString("name");
int price=json2.getInt("price");
JSONArray jarray=json2.getJSONArray("attributes");
//JSONArray jarray1=json1.getJSONArray("capacity");
int a= json2.size();
for(int i=0;i<json2.size();i++)
{
System.out.println("The id is "+ json2.getDouble("id"));
System.out.println("The name is "+ json2.getString("name"));
System.out.println("The price is "+ json2.getInt("price"));
System.out.println("the size of object is" + a);
}
/* for(int i=0;i<jarray.size();i++)
{
System.out.println("This is ameneities id is " + jarray.getString(i));
}
for(int j=0;j<jarray1.size();j++)
{
System.out.println("This is ameneities id is " + jarray1.getString(j));
}*/
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
が、それは私の最初のidと次のIDのようなただ一つのオブジェクトを与えているが、ループのためにアクセスすることはできません。
少ないがもっとある... – nfechner
(私達にあなたのコードを表示し、[すでに試してみました何]を教えてくださいhttp://mattgemmell.com/2008/12/08/what-have-you-tried /)。 – nfechner
私はこのようなことをしました。 –