本文整理汇总了Java中com.alibaba.fastjson.JSONArray.toJSONString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.toJSONString方法的具体用法?Java JSONArray.toJSONString怎么用?Java JSONArray.toJSONString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSONArray
的用法示例。
在下文中一共展示了JSONArray.toJSONString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processPipeline
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
private void processPipeline(Pipeline pipeline) {
Estimate e = new Estimate(pipeline.getNo(), "0");
SysConfig.CurEstimate.add(e);
saveCurEstimate();
SysConfig.PipelineList.add(pipeline);
String aJson = JSONArray.toJSONString(SysConfig.PipelineList);
// write to local
try {
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/cashe.txt");
// HdfsUtil hdfsUtil = HdfsUtil.getHdfsUtil();
// write to hdfs
// hdfsUtil.copyFile(SysConfig.Catalog_Project + "cashe/cashe.txt", SysConfig.Catalog_Cashe);
// hdfsUtil.upFile(names.get(2), SysConfig.Catalog_Pipeline +"/"+ names.get(6) + "/schema.txt");
// GENERATE_DDL, GENERATE_LOAD
CmdReceiver instance = CmdReceiver.getInstance(pipeline);
instance.generateDDL(false);
instance.generateLoad(false);
// load data in producing clusters(mini batch)
savePipelineState(pipeline, SysConfig.PipelineState[1]);
changeState(pipeline.getNo(), 1);
// loadDataByPipeline(pipeline);
} catch (IOException ee) {
ee.printStackTrace();
}
}
示例2: savePipelineState
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void savePipelineState(Pipeline pipeline, String state) {
String time = DateUtil.formatTime(new Date());
State s = new State(time, state);
Process p = searchProcessByPno(pipeline.getNo());
if (p != null) {
p.getPipelineState().add(s);
} else {
List<State> PipelineState = new ArrayList<>();
PipelineState.add(s);
p = new Process(pipeline.getNo(), PipelineState);
SysConfig.ProcessList.add(p);
}
String processListJson = JSONArray.toJSONString(SysConfig.ProcessList);
try {
FileUtil.writeFile(processListJson, SysConfig.Catalog_Project + "cashe/process.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: updatePipelineList
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
private void updatePipelineList(boolean flag) {
String aJson = JSONArray.toJSONString(SysConfig.PipelineList);
try {
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/cashe.txt");
// remove process
if (flag) {
aJson = JSONArray.toJSONString(SysConfig.ProcessList);
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/process.txt");
aJson = JSONArray.toJSONString(SysConfig.CurLayout);
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/curLayout.txt");
aJson = JSONArray.toJSONString(SysConfig.CurOrderedLayout);
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/orderedLayout.txt");
aJson = JSONArray.toJSONString(SysConfig.CurEstimate);
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/curEstimate.txt");
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例4: ProcessTest
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@Test
public void ProcessTest() throws IOException {
String time = DateUtil.formatTime(new Date());
String state = SysConfig.PipelineState[0];
State s = new State(time, state);
List<State> pipelineState = new ArrayList<>();
pipelineState.add(s);
s = new State(DateUtil.formatTime(new Date()), SysConfig.PipelineState[1]);
pipelineState.add(s);
s = new State(DateUtil.formatTime(new Date()), SysConfig.PipelineState[2]);
pipelineState.add(s);
Process p = new Process("3fd97c0a9714cc7ea8d3277c535483cb", pipelineState);
SysConfig.ProcessList.add(p);
String aJson = JSONArray.toJSONString(SysConfig.ProcessList);
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/process.txt");
}
示例5: toSendMsg
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public String toSendMsg(){
JSONArray array = new JSONArray();
if(msg == null || msg.length == 0){
array.add("");
}else{
for (Object m : msg) {
if(String.class == m.getClass()){
array.add(m);
}else if (Integer.class == m.getClass()){
JSONArray faceArray = new JSONArray();
faceArray.add("face");
faceArray.add((Integer)m);
array.add(faceArray);
}
}
}
array.add(font.toFontArray());
return array.toJSONString();
}
示例6: test_for_issue
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
Date now = new Date();
GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
gregorianCalendar.setTime(now);
XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);
String jsonString = JSON.toJSONString(calendar);
// success
calendar = JSON.parseObject(jsonString, XMLGregorianCalendar.class);
Object toJSON1 = JSON.toJSON(calendar); // debug看到是 Long 类型
// 所以这里会报错:
// error: java.lang.ClassCastException: java.lang.Long cannot be cast to com.alibaba.fastjson.JSONObject
//JSONObject jsonObject = (JSONObject) JSON.toJSON(calendar);
// 所以 这里肯定会报错, 因为 jsonObject 不是JSONObject类型
//calendar = jsonObject.toJavaObject(XMLGregorianCalendar.class);
List<XMLGregorianCalendar> calendarList = new ArrayList<XMLGregorianCalendar>();
calendarList.add(calendar);
calendarList.add(calendar);
calendarList.add(calendar);
Object toJSON2 = JSON.toJSON(calendarList); // debug 看到是 JSONArray 类型
// success: 通过 JSONArray.parseArray 方法可以正确转换
JSONArray jsonArray = (JSONArray) JSON.toJSON(calendarList);
jsonString = jsonArray.toJSONString();
List<XMLGregorianCalendar> calendarList1 = JSONArray.parseArray(jsonString, XMLGregorianCalendar.class);
// 通过 jsonArray.toJavaList 无法转换
// error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);
assertNotNull(calendarList2);
assertEquals(3, calendarList2.size());
}
示例7: changeState
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
private void changeState(String pno, int state) {
for (Pipeline p : SysConfig.PipelineList) {
if (p.getNo().equals(pno)) {
p.setState(state);
break;
}
}
String aJson = JSONArray.toJSONString(SysConfig.PipelineList);
try {
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/cashe.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
示例8: saveCurLayout
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
private void saveCurLayout() {
String aJson = JSONArray.toJSONString(SysConfig.CurLayout);
try {
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/curLayout.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
示例9: saveCurEstimate
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
private void saveCurEstimate() {
String aJson = JSONArray.toJSONString(SysConfig.CurEstimate);
try {
FileUtil.writeFile(aJson, SysConfig.Catalog_Project + "cashe/curEstimate.txt");
} catch (IOException e) {
e.printStackTrace();
}
}
示例10: toString
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**
* To JSON string.
*/
@Override
public String toString() {
return JSONArray.toJSONString(this);
}
示例11: run
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**
* 开始处理每一行数据 <br/>
* @author jingma
* @return
* @throws KettleException
*/
public boolean run() throws Exception{
Object[] r = ku.getRow(); // get row, blocks when needed!
if (r == null) // no more input to be expected...
{
end();
ku.setOutputDone();
return false;
}
if (ku.first) {
data.outputRowMeta = (RowMetaInterface) ku.getInputRowMeta().clone();
getFields(data.outputRowMeta, ku.getStepname(), null, null, ku);
ku.first = false;
init();
}
//创建输出记录
Object[] outputRow = RowDataUtil.createResizedCopy( r, data.outputRowMeta.size() );
//验证信息
JSONArray validateInfo = new JSONArray();
for(JSONObject vi:configInfo.getJSONArray(VALIDATE_INFO).toArray(new JSONObject[]{})){
switch (vi.getString(VALIDATE_RULE)) {
case RULE_NOT_EMPTY:
validateNotEmpty(outputRow[getFieldIndex(vi.getString(VALIDATE_FIELD))],vi,validateInfo);
break;
case RULE_DATE_FORMAT:
validateDateFormat(outputRow[getFieldIndex(vi.getString(VALIDATE_FIELD))],vi,validateInfo);
break;
case RULE_SFZH:
validateSfzh(outputRow[getFieldIndex(vi.getString(VALIDATE_FIELD))],vi,validateInfo);
break;
case RULE_IN:
validateIn(outputRow[getFieldIndex(vi.getString(VALIDATE_FIELD))],vi,validateInfo);
break;
case RULE_NOT_IN:
validateNotIn(outputRow[getFieldIndex(vi.getString(VALIDATE_FIELD))],vi,validateInfo);
break;
case RULE_LIKE:
validateLike(outputRow[getFieldIndex(vi.getString(VALIDATE_FIELD))],vi,validateInfo);
break;
case RULE_NOT_LIKE:
validateNotLike(outputRow[getFieldIndex(vi.getString(VALIDATE_FIELD))],vi,validateInfo);
break;
default:
ku.logError("未知的验证:"+vi.getString(VALIDATE_RULE));
break;
}
}
if(validateInfo.size()>0){
if(RESULT_VALIDATE_INFO.equals(configInfo.getString(RESULT_DISPOSE))){
outputRow[getFieldIndex(FIELD_VALIDATE_INFO)] = validateInfo.toJSONString();
//将该记录设置到下一步骤的读取序列中
ku.putRow(data.outputRowMeta, outputRow); // copy row to possible alternate rowset(s)
}else if(RESULT_CONTINUE.equals(configInfo.getString(RESULT_VALIDATE_INFO))){
//跳过
}
}else{
//将该记录设置到下一步骤的读取序列中
ku.putRow(data.outputRowMeta, outputRow); // copy row to possible alternate rowset(s)
}
return true;
}