我有一个现有的200MB JSON文件:yelp_training_set_review.json`。
{"votes": "1", "funny": "2", "useful": "3"} {"votes ":" 4 "," funny ":" 5 "," useful ":" 6 "} {" votes ":" 7 "," funny ":" 8 "," useful ":" 9 "}......
请注意,两个对象{}之间没有逗号,我只能使用以下代码来解析第一个对象(一个{})。
如何获取文件中对象的大小,或如何解析所有对象?
public static void main(String[] args) throws Exception {
JSONObject jsonobject = new JSONObject(new JSONTokener(new FileReader(
new File("C:\\yelp_training_set_review.json"))));
for (int i = 0; i < jsonobject.length(); i++) {
int k = jsonobject.length();
System.out.println(jsonobject.getString("votes "));
System.out.println(jsonobject.getString("funny "));
System.out.println(jsonobject.getString("useful "));
}
}
我已经解决了这个问题。使用,
while(temp!=null){
teststring=temp;
temp=br.readLine();
System.out.println(teststring);
JSONTokener jsonParser = new JSONTokener(teststring);
JSONObject jsonobject=new JSONObject(jsonParser);
JSONObject VotejsonObject = jsonobject.getJSONObject("votes");
System.out.println(VotejsonObject.getInt("funny"));
System.out.println(VotejsonObject.getInt("useful"));
System.out.println(VotejsonObject.getInt("cool"));
System.out.println(jsonobject.getString("user_id"));
System.out.println(jsonobject.getString("review_id"));
System.out.println(jsonobject.getInt("stars"));
System.out.println(jsonobject.getString("date"));
System.out.println(jsonobject.getString("text"));
System.out.println(jsonobject.getString("type"));
System.out.println(jsonobject.getString("business_id"));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句