org.json.CDL#toJSONArray ( )源码实例Demo

下面列出了org.json.CDL#toJSONArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Attempt to create a JSONArray with an escape quote and no enclosing quotes.
 * Expects a JSONException. 
 */
@Test
public void badEscapedQuote(){
	       String badLine = "Col1, Col2\nVal1, \"\"Val2";
	       
	       try {
               CDL.toJSONArray(badLine);
               fail("Expecting an exception");
           } catch (JSONException e) {
        	   System.out.println("Message" + e.getMessage());
               assertEquals("Expecting an exception message",
                       "Bad character 'V' (86). at 20 [character 9 line 2]",
                       e.getMessage());
               
           }
           
}
 
源代码2 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Attempts to create a JSONArray from a string with unbalanced quotes
 * in column title line. Expects a JSONException.
 */
@Test
public void unbalancedQuoteInName() {
    String badLine = "Col1, \"Col2\nVal1, Val2";
    try {
        CDL.toJSONArray(badLine);
        fail("Expecting an exception");
    } catch (JSONException e) {
        assertEquals("Expecting an exception message",
                "Missing close quote '\"'. at 12 [character 0 line 2]",
                e.getMessage());
    }
}
 
源代码3 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Attempts to create a JSONArray from a string with unbalanced quotes
 * in value line. Expects a JSONException.
 */
@Test
public void unbalancedQuoteInValue() {
    String badLine = "Col1, Col2\n\"Val1, Val2";
    try {
        CDL.toJSONArray(badLine);
        fail("Expecting an exception");
    } catch (JSONException e) {
        assertEquals("Expecting an exception message",
                "Missing close quote '\"'. at 22 [character 11 line 2]",
                e.getMessage());
        
    }
}
 
源代码4 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Attempts to create a JSONArray from a string with null char
 * in column title line. Expects a JSONException.
 */
@Test
public void nullInName() {
    String badLine = "C\0ol1, Col2\nVal1, Val2";
    try {
        CDL.toJSONArray(badLine);
        fail("Expecting an exception");
    } catch (JSONException e) {
        assertEquals("Expecting an exception message",
                "Bad character 'o' (111). at 2 [character 3 line 1]",
                e.getMessage());
        
    }
}
 
源代码5 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Attempt to create a JSONArray with unbalanced quotes and a properly escaped doubled quote.
 * Expects a JSONException. 
 */
@Test
public void unbalancedEscapedQuote(){
	   String badLine = "Col1, Col2\n\"Val1, \"\"Val2\"\"";
       try {
           CDL.toJSONArray(badLine);
           fail("Expecting an exception");
       } catch (JSONException e) {
           assertEquals("Expecting an exception message",
                   "Missing close quote '\"'. at 26 [character 15 line 2]",
                   e.getMessage());
           
       }
}
 
源代码6 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Assert that there is no error for a single escaped quote within a properly embedded quote.
 */
@Test
public void singleEscapedQuote(){
           String singleEscape = "Col1, Col2\nVal1, \"\"\"Val2\"";
           JSONArray jsonArray = CDL.toJSONArray(singleEscape);
           
           String cdlStr = CDL.toString(jsonArray);
           assertTrue(cdlStr.contains("Col1"));
           assertTrue(cdlStr.contains("Col2"));
           assertTrue(cdlStr.contains("Val1"));
           assertTrue(cdlStr.contains("\"Val2"));
}
 
源代码7 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Assert that there is no error for a single escaped quote within a properly
 * embedded quote when not the last value.
 */
@Test
public void singleEscapedQuoteMiddleString(){
           String singleEscape = "Col1, Col2\nVal1, \"\"\"Val2\"\nVal 3,Val 4";
           JSONArray jsonArray = CDL.toJSONArray(singleEscape);
           
           String cdlStr = CDL.toString(jsonArray);
           assertTrue(cdlStr.contains("Col1"));
           assertTrue(cdlStr.contains("Col2"));
           assertTrue(cdlStr.contains("Val1"));
           assertTrue(cdlStr.contains("\"Val2"));
}
 
源代码8 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Create a JSONArray from an empty string
 */
@Test
public void emptyString() {
    String emptyStr = "";
    JSONArray jsonArray = CDL.toJSONArray(emptyStr);
    assertTrue("CDL should return null when the input string is empty",
            jsonArray == null);
}
 
源代码9 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Create a JSONArray with only 1 row
 */
@Test
public void onlyColumnNames() {
    String columnNameStr = "col1, col2, col3";
    JSONArray jsonArray = CDL.toJSONArray(columnNameStr);
    assertNull("CDL should return null when only 1 row is given",
            jsonArray);
}
 
源代码10 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Create a JSONArray from string containing only whitespace and commas
 */
@Test
public void emptyLinesToJSONArray() {
    String str = " , , , \n , , , ";
    JSONArray jsonArray = CDL.toJSONArray(str);
    assertNull("JSONArray should be null for no content",
            jsonArray);
}
 
源代码11 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Create a JSONArray from a string of lines
 */
@Test
public void textToJSONArray() {
    JSONArray jsonArray = CDL.toJSONArray(this.lines);
    JSONArray expectedJsonArray = new JSONArray(this.expectedLines);
    Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray);
}
 
源代码12 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Create a JSONArray from a JSONArray of titles and a 
 * string of value lines
 */
@Test
public void jsonArrayToJSONArray() {
    String nameArrayStr = "[Col1, Col2]";
    String values = "V1, V2";
    JSONArray nameJSONArray = new JSONArray(nameArrayStr);
    JSONArray jsonArray = CDL.toJSONArray(nameJSONArray, values);
    JSONArray expectedJsonArray = new JSONArray("[{Col1:V1,Col2:V2}]");
    Util.compareActualVsExpectedJsonArrays(jsonArray, expectedJsonArray);
}
 
源代码13 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Create a JSONArray from a string of lines,
 * then convert to string and then back to JSONArray
 */
@Test
public void textToJSONArrayAndBackToString() {
    JSONArray jsonArray = CDL.toJSONArray(this.lines);
    String jsonStr = CDL.toString(jsonArray);
    JSONArray finalJsonArray = CDL.toJSONArray(jsonStr);
    JSONArray expectedJsonArray = new JSONArray(this.expectedLines);
    Util.compareActualVsExpectedJsonArrays(finalJsonArray, expectedJsonArray);
}
 
源代码14 项目: tutorials   文件: CDLDemo.java
public static void jaOfJOFromCDT() {
    String string = 
      "name, city, age \n" +
      "john, chicago, 22 \n" +
      "gary, florida, 35 \n" +
      "sal, vegas, 18";
     
    JSONArray result = CDL.toJSONArray(string);
    System.out.println(result.toString());
}
 
源代码15 项目: tutorials   文件: CDLDemo.java
public static void jaOfJOFromCDT2() {
    JSONArray ja = new JSONArray();
    ja.put("name");
    ja.put("city");
    ja.put("age");
     
    String string = 
      "john, chicago, 22 \n" +
      "gary, florida, 35 \n" +
      "sal, vegas, 18";
     
    JSONArray result = CDL.toJSONArray(ja, string);
    System.out.println(result.toString());
}
 
源代码16 项目: tutorials   文件: CDLIntegrationTest.java
@Test
public void givenCommaDelimitedText_thenGetJSONArrayOfJSONObjects() {
    String string = 
      "name, city, age \n" +
      "john, chicago, 22 \n" +
      "gary, florida, 35 \n" +
      "sal, vegas, 18";
     
    JSONArray result = CDL.toJSONArray(string);
    assertEquals("[{\"name\":\"john\",\"city\":\"chicago\",\"age\":\"22\"},{\"name\":\"gary\",\"city\":\"florida\",\"age\":\"35\"},{\"name\":\"sal\",\"city\":\"vegas\",\"age\":\"18\"}]", result.toString());
}
 
源代码17 项目: tutorials   文件: CDLIntegrationTest.java
@Test
public void givenCommaDelimitedText_thenGetJSONArrayOfJSONObjects2() {
    JSONArray ja = new JSONArray();
    ja.put("name");
    ja.put("city");
    ja.put("age");
     
    String string = 
      "john, chicago, 22 \n" +
      "gary, florida, 35 \n" +
      "sal, vegas, 18";
     
    JSONArray result = CDL.toJSONArray(ja, string);
    assertEquals("[{\"name\":\"john\",\"city\":\"chicago\",\"age\":\"22\"},{\"name\":\"gary\",\"city\":\"florida\",\"age\":\"35\"},{\"name\":\"sal\",\"city\":\"vegas\",\"age\":\"18\"}]", result.toString());
}
 
源代码18 项目: JSON-Java-unit-test   文件: CDLTest.java
/**
 * Attempts to create a JSONArray from a null string.
 * Expect a NullPointerException.
 */
@Test(expected=NullPointerException.class)
public void exceptionOnNullString() {
    String nullStr = null;
    CDL.toJSONArray(nullStr);
}
 
 方法所在类