0
對於上述代碼的Groovy錯誤它出現在上蝕
錯誤「如果(recJsonObj的instanceof的JSONObject){」線路 我完全新到groovy.code作爲bellows..what可以是誤差Δθ ?我真的很沮喪這個language.help我..
import org.json.*;
class Convert {
def JSONDifference(JSONObject recJsonObj, JSONObject expJsonObj){
//File logFile = new File("C:\\TestCases\\my1.txt")
def pass = true
def recArrStrElements = recJsonObj.getNames(recJsonObj)
def expArrStrElements = expJsonObj.getNames(expJsonObj)
def found = false
def foundMacthForCurrentElement = false
for (int x = 0; x < recArrStrElements.size(); x++) {
def recCurrVal = recJsonObj.get(recArrStrElements[x].toString())
foundMacthForCurrentElement = false
for (int y = 0; y < expArrStrElements.size(); y++) {
def expCurrVal = expJsonObj.get(expArrStrElements[y].toString())
if(recArrStrElements[x] == expArrStrElements[y]){
if(recCurrVal instanceof JSONArray){
recCurrValJsonArray = (JSONArray)recCurrVal
expCurrValJsonArray = (JSONArray)expCurrVal
for(int i = 0; i<recCurrValJsonArray.length(); i++){
recNestedJsonObj = recCurrValJsonArray.get(i)
//for(int j = 0; j<expCurrValJsonArray.length(); j++){
//if(foundMacthForCurrentElement){break}
//else{
expNestedJsonObj = expCurrValJsonArray.get(i)
if(recNestedJsonObj instanceof JSONObject){
foundMatch = JSONDifference(recNestedJsonObj, expNestedJsonObj)
}
else{
}
// if(foundMatch){
// foundMacthForCurrentElement = true
// }
//}
//}
}
found=true
}
else if(recCurrVal instanceof JSONObject){
recCurrValJSONObject = (JSONObject)recCurrVal
expCurrValJSONObject = (JSONObject)expCurrVal
JSONDifference(recCurrValJSONObject, expCurrValJSONObject)
found=true
}
else{
if(recCurrVal == expCurrVal){
//log.info "Element matched " + recCurrVal + ":" + recArrStrElements[x]
//logFile.append("Matched "+recArrStrElements[x])
//logFile.append("\n")
found=true
}
else{
found=false
}
}
}
}
if (!found){
pass = false
log.info "Element not received " + recArrStrElements[x] + ":"+ recCurrVal + " ====/==== " + expJsonObj.get(expArrStrElements[x].toString())
//logFile.append("Element not received " + recArrStrElements[x] + ":" + recCurrVal)
//logFile.append("\n")
}
//logFile.append(arrStrElements[x].toString())
//logFile.append("-")
//logFile.append(currVal.toString())
//logFile.append("\n")
//if(currVal.contains("{")){
// JSONObject nestedJsonObj = new JSONObject(arrStrElements[x].toString)
// JSONDifference(nestedJsonObj)
//}
}
return pass
}
if(recJsonObj instanceof JSONObject){
JSONObject jsonObjRec = new JSONObject(expJSONResp)
JSONObject jsonObjExp = new JSONObject(resJSONResp)
temp = JSONDifference(jsonObjRec, jsonObjExp)
}
else{
expSplitString = expJSONResp.split("\n")
resSplitString = resJSONResp.split("\n")
for (int a = 0; a < expSplitString.size(); a++) {
foundMacthForCurrentElement = false
int b = 0
while (b < resSplitString.size() && !foundMacthForCurrentElement) {
//log.info expSplitString[a] + " |||| " + resSplitString[b]
if (expSplitString[a].replaceAll("\\s+","")==resSplitString[b].replaceAll("\\s+","")){
foundMacthForCurrentElement = true
}
b++
}
if(!foundMacthForCurrentElement){
log.info "Element not received :- " + expSplitString[a].replaceAll("\\s+","") + " ====/==== " + resSplitString[a].replaceAll("\\s+","")
}
}
}
}
您應該嘗試儘可能多地去除代碼,並向我們展示尚未解決問題的最小代碼。 – Gangnus
並且不要忘記向我們展示發生的具體錯誤消息。 –
你想做什麼?和什麼是挑戰?提供確切的錯誤信息 – Motilal