{
int last = fixup.length()-1;
if (last<0)
{
throw new JSONException("fixup path must contain at least 1 reference");
}
Object originalObject = traverse(arguments, original, false);
Object fixupParent = traverse(arguments, fixup, true);
// the last ref in the fixup needs to be created
// it will be either a string or number depending on if the fixupParent is a JSONObject or JSONArray
if (fixupParent instanceof JSONObject)
{
String objRef = fixup.optString(last,null);
if (objRef == null)
{
throw new JSONException("last fixup reference not a string");
}
((JSONObject)fixupParent).put(objRef, originalObject);
}
else
{
int arrRef = fixup.optInt(last,-1);
if (arrRef==-1)
{
throw new JSONException("last fixup reference not a valid array index");
}
((JSONArray)fixupParent).put(arrRef, originalObject);
}
}