假設你的JSON看起來像這樣:
String jsonToDecode = "{" +
" \"hostId\" : 286,\n" +
" \"parentSectionName\" : \"adadfr\",\n" +
" \"rank\" : 86096.0,\n" +
" \"activationStatus\" : \"ACTIVE\",\n" +
" \"overrideLinkProp\" : 0,"+
"}";
您可以使用 「com.googlecode.json - 簡單的」 包裝像這樣對其進行解碼:
JSONParser parser = new JSONParser();
Object parsedJson = new Object();
try {
parsedJson = parser.parse(jsonToDecode);
} catch (ParseException e) {
//do something when json parsing fails
}
JSONObject jsonObject = (JSONObject) parsedJson;
String name = (String) jsonObject.get("parentSectionName");
System.out.print(name); // will output adadfr
有各種天秤座你可以根據你使用的語言來解析'JSON'。選一個對你看起來很好的人。它可能是你的'selenium'測試的一部分,但是你不會使用'selenium'庫來處理'JSON'對象。 – mrfreester