Пример #1
0
 /**
  * Get the next value. The value can be wrapped in quotes. The value can be empty.
  *
  * @param x A JSONTokener of the source text.
  * @return The value string, or null if empty.
  * @throws JSONException if the quoted string is badly formed.
  */
 private static String getValue(JSONTokener x) throws JSONException {
   char c;
   do {
     c = x.next();
   } while (c <= ' ' && c != 0);
   switch (c) {
     case 0:
       return null;
     case '"':
     case '\'':
       return x.nextString(c);
     case ',':
       x.back();
       return "";
     default:
       x.back();
       return x.nextTo(',');
   }
 }
Пример #2
0
 /**
  * Produce a JSONArray of strings from a row of comma delimited values.
  *
  * @param x A JSONTokener of the source text.
  * @return A JSONArray of strings.
  * @throws JSONException
  */
 public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException {
   JSONArray ja = new JSONArray();
   for (; ; ) {
     String value = getValue(x);
     if (value == null) {
       return null;
     }
     ja.put(value);
     for (; ; ) {
       char c = x.next();
       if (c == ',') {
         break;
       }
       if (c != ' ') {
         if (c == '\n' || c == '\r' || c == 0) {
           return ja;
         }
         throw x.syntaxError("Bad character '" + c + "' (" + (int) c + ").");
       }
     }
   }
 }