json parsing list value, json multi-layer value

demand

Get the json file first, and parse it as follows to get the required field values, which can be saved or returned by the set value of the new object.

	package UserTest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class JsonTest {

public static void main(String[] args) {
	
	JSONObject json= new JSONObject();
	
	json =JSON.parseObject("{'result':{'AccuracyScore':4.03757,'TotalScore':4.032336,'IsRejected':false,'SSID':'see273db75f@gz282d0c5224303c2a00','FluencyScore':5,'IntegrityScore':5,'AdditionalInfo':{},'ExceptInfo':0,'Sentences':[{'AccuracyScore':4.03757,'TotalScore':4.518785,'Index':0,'FluencyScore':5,'BegPos':0,'EndPos':9420,'Content':'shall we let the cat out of the bag','Words':[{'Index':0,'DpMsg':0,'Score':2.836047,'GlobalIndex':0,'WerrMsg':0,'Content':'shall','PitchBeg':0,'Pitch':'','BegPos':640,'PitchEnd':0,'Property':0,'EndPos':1050,'Sylls':[{'Phones':[{'EndPos':880,'Content':'sh','DpMsg':0,'BegPos':640},{'EndPos':1020,'Content':'ae','DpMsg':0,'BegPos':880},{'EndPos':1050,'Content':'l','DpMsg':0,'BegPos':1020}],'Content':'sh ae l','BegPos':640,'EndPos':1050,'SerrMsg':1,'Accent':0}]},{'Index':1,'DpMsg':0,'Score':1.839397,'GlobalIndex':1,'WerrMsg':0,'Content':'we','PitchBeg':0,'Pitch':'','BegPos':1050,'PitchEnd':0,'Property':0,'EndPos':1220,'Sylls':[{'Phones':[{'EndPos':1120,'Content':'w','DpMsg':0,'BegPos':1050},{'EndPos':1220,'Content':'iy','DpMsg':0,'BegPos':1120}],'Content':'w iy','BegPos':1050,'EndPos':1220,'SerrMsg':0,'Accent':0}]},{'Index':2,'DpMsg':0,'Score':4.724759,'GlobalIndex':2,'WerrMsg':0,'Content':'let','PitchBeg':0,'Pitch':'','BegPos':1220,'PitchEnd':0,'Property':0,'EndPos':1600,'Sylls':[{'Phones':[{'EndPos':1320,'Content':'l','DpMsg':0,'BegPos':1220},{'EndPos':1420,'Content':'eh','DpMsg':0,'BegPos':1320},{'EndPos':1600,'Content':'t','DpMsg':0,'BegPos':1420}],'Content':'l eh t','BegPos':1220,'EndPos':1600,'SerrMsg':0,'Accent':0}]},{'Index':3,'DpMsg':0,'Score':3.16817,'GlobalIndex':3,'WerrMsg':0,'Content':'the','PitchBeg':0,'Pitch':'','BegPos':1600,'PitchEnd':0,'Property':0,'EndPos':1800,'Sylls':[{'Phones':[{'EndPos':1740,'Content':'dh','DpMsg':0,'BegPos':1600},{'EndPos':1800,'Content':'ax','DpMsg':0,'BegPos':1740}],'Content':'dh ax','BegPos':1600,'EndPos':1800,'SerrMsg':0,'Accent':0}]},{'Index':4,'DpMsg':0,'Score':4.450028,'GlobalIndex':4,'WerrMsg':0,'Content':'cat','PitchBeg':0,'Pitch':'','BegPos':1800,'PitchEnd':0,'Property':0,'EndPos':2280,'Sylls':[{'Phones':[{'EndPos':1920,'Content':'k','DpMsg':0,'BegPos':1800},{'EndPos':2080,'Content':'ae','DpMsg':0,'BegPos':1920},{'EndPos':2280,'Content':'t','DpMsg':0,'BegPos':2080}],'Content':'k ae t','BegPos':1800,'EndPos':2280,'SerrMsg':0,'Accent':0}]},{'Index':5,'DpMsg':0,'Score':3.076916,'GlobalIndex':5,'WerrMsg':0,'Content':'out','PitchBeg':0,'Pitch':'','BegPos':2280,'PitchEnd':0,'Property':0,'EndPos':2660,'Sylls':[{'Phones':[{'EndPos':2540,'Content':'aw','DpMsg':0,'BegPos':2280},{'EndPos':2660,'Content':'t','DpMsg':0,'BegPos':2540}],'Content':'aw t','BegPos':2280,'EndPos':2660,'SerrMsg':0,'Accent':0}]},{'Index':6,'DpMsg':0,'Score':3.030843,'GlobalIndex':6,'WerrMsg':0,'Content':'of','PitchBeg':0,'Pitch':'','BegPos':2660,'PitchEnd':0,'Property':0,'EndPos':3080,'Sylls':[{'Phones':[{'EndPos':2920,'Content':'ax','DpMsg':0,'BegPos':2660},{'EndPos':3080,'Content':'v','DpMsg':0,'BegPos':2920}],'Content':'ax v','BegPos':2660,'EndPos':3080,'SerrMsg':0,'Accent':0}]},{'Index':7,'DpMsg':0,'Score':4.411788,'GlobalIndex':7,'WerrMsg':0,'Content':'the','PitchBeg':0,'Pitch':'','BegPos':3080,'PitchEnd':0,'Property':0,'EndPos':3240,'Sylls':[{'Phones':[{'EndPos':3180,'Content':'dh','DpMsg':0,'BegPos':3080},{'EndPos':3240,'Content':'ax','DpMsg':0,'BegPos':3180}],'Content':'dh ax','BegPos':3080,'EndPos':3240,'SerrMsg':0,'Accent':0}]},{'Index':8,'DpMsg':0,'Score':3.476231,'GlobalIndex':8,'WerrMsg':0,'Content':'bag','PitchBeg':0,'Pitch':'','BegPos':3240,'PitchEnd':0,'Property':0,'EndPos':3720,'Sylls':[{'Phones':[{'EndPos':3380,'Content':'b','DpMsg':0,'BegPos':3240},{'EndPos':3500,'Content':'ae','DpMsg':0,'BegPos':3380},{'EndPos':3720,'Content':'g','DpMsg':0,'BegPos':3500}],'Content':'b ae g','BegPos':3240,'EndPos':3720,'SerrMsg':0,'Accent':0}]}]}]},'resultType':4}");
   
	String js=json.get("result").toString();
	
	json=JSON.parseObject(js);
	
	JSONArray ja=(JSONArray) json.get("Sentences");
	
	for(int i=0;i<ja.size();i++){
		js=ja.get(i).toString();
		json=JSON.parseObject(js);
		JSONArray jsa=(JSONArray) json.get("Words");
		for(int j=0;j<jsa.size();j++){
		js=jsa.get(j).toString();
		json=JSON.parseObject(js);
		switch(j){
		case 0:String score0=json.get("Score").toString();
		System.out.println(score0);
		break;
		case 1:String score1=json.get("Score").toString();
		System.out.println(score1);
		break;
		case 2:String score2=json.get("Score").toString();break;
		case 3:String score3=json.get("Score").toString();break;
		case 4:String score4=json.get("Score").toString();break;
		case 5:String score5=json.get("Score").toString();break;
		case 6:String score6=json.get("Score").toString();break;
		case 7:String score7=json.get("Score").toString();break;
		case 8:String score8=json.get("Score").toString();break;	
		case 9:String score9=json.get("Score").toString();break;
		}
		
		}
	}
}

	
	
}		
										

Guess you like

Origin blog.csdn.net/qq_37980436/article/details/70738355