本文整理汇总了Java中org.json.CDL.toString方法的典型用法代码示例。如果您正苦于以下问题:Java CDL.toString方法的具体用法?Java CDL.toString怎么用?Java CDL.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.CDL
的用法示例。
在下文中一共展示了CDL.toString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkSpecialChars
import org.json.CDL; //导入方法依赖的package包/类
/**
* Given a JSONArray that was not built by CDL, some chars may be
* found that would otherwise be filtered out by CDL.
*/
@Test
public void checkSpecialChars() {
JSONArray jsonArray = new JSONArray();
JSONObject jsonObject = new JSONObject();
jsonArray.put(jsonObject);
// \r will be filtered from name
jsonObject.put("Col \r1", "V1");
// \r will be filtered from value
jsonObject.put("Col 2", "V2\r");
assertTrue("expected length should be 1",jsonArray.length() == 1);
String cdlStr = CDL.toString(jsonArray);
jsonObject = jsonArray.getJSONObject(0);
assertTrue(cdlStr.contains("\"Col 1\""));
assertTrue(cdlStr.contains("Col 2"));
assertTrue(cdlStr.contains("V1"));
assertTrue(cdlStr.contains("\"V2\""));
}
示例2: singleEscapedQuote
import org.json.CDL; //导入方法依赖的package包/类
/**
* 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"));
}
示例3: singleEscapedQuoteMiddleString
import org.json.CDL; //导入方法依赖的package包/类
/**
* 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"));
}
示例4: emptyJSONArrayToString
import org.json.CDL; //导入方法依赖的package包/类
/**
* call toString with a null array
*/
@Test
public void emptyJSONArrayToString() {
JSONArray jsonArray = new JSONArray();
String str = CDL.toString(jsonArray);
assertNull("CDL should return null for toString(null)",
str);
}
示例5: nullJSONArraysToString
import org.json.CDL; //导入方法依赖的package包/类
/**
* call toString with a null arrays for names and values
*/
@Test
public void nullJSONArraysToString() {
String str = CDL.toString(null, null);
assertNull("CDL should return null for toString(null)",
str);
}
示例6: textToJSONArrayAndBackToString
import org.json.CDL; //导入方法依赖的package包/类
/**
* 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(lines);
String jsonStr = CDL.toString(jsonArray);
JSONArray finalJsonArray = CDL.toJSONArray(jsonStr);
JSONArray expectedJsonArray = new JSONArray(expectedLines);
Util.compareActualVsExpectedJsonArrays(finalJsonArray, expectedJsonArray);
}
示例7: nullJSONArrayToString
import org.json.CDL; //导入方法依赖的package包/类
/**
* call toString with a null array
*/
@Test(expected=NullPointerException.class)
public void nullJSONArrayToString() {
CDL.toString((JSONArray)null);
}