/** * Parses a StringBuilder into its correct equivalent JSON value, starting at a specific position */ public static JSONValue parse(StringBuilder input, int position) { // Decides what it is if (JSONObject.matchesInput(input, position)) { return(new JSONObject(input, position)); } else if (JSONArray.matchesInput(input, position)) { return(new JSONArray(input, position)); } else if (JSONString.matchesInput(input, position)) { return(new JSONString(input, position)); } else if (JSONNumber.matchesInput(input, position)) { return(new JSONNumber(input, position)); } else if (JSONLiteral.matchesInput(input, position)) { return(new JSONLiteral(input, position)); } else { // Invalid Debug.LogError("No valid type found when parsing " + input + " @ " + position + " (" + input.ToString(position, input.Length - position) + ")"); return(null); } }
/** * Encodes an object into a string, correctly identifying the type */ public static string encode(object value, int indentLevel, JSONStringifyOptions options) { // Decides what it is if (JSONArray.matchesValue(value)) { return(new JSONArray(value).ToString(indentLevel, options)); } else if (JSONString.matchesValue(value)) { return(new JSONString(value).ToString(indentLevel, options)); } else if (JSONNumber.matchesValue(value)) { return(new JSONNumber(value).ToString(indentLevel, options)); } else if (JSONLiteral.matchesValue(value)) { return(new JSONLiteral(value).ToString(indentLevel, options)); } else { return(new JSONObject(value).ToString(indentLevel, options)); } }