當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONArray.toJSONString方法代碼示例

本文整理匯總了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();
        }
    }
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:26,代碼來源:RwMain.java

示例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();
    }
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:20,代碼來源:RwMain.java

示例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();
    }
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:23,代碼來源:RwMain.java

示例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");

}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:22,代碼來源:ProcessStateTest.java

示例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();
}
 
開發者ID:thankjava,項目名稱:smartqq-agreement-core,代碼行數:21,代碼來源:Content.java

示例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());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:38,代碼來源:Issue1023.java

示例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();
    }
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:15,代碼來源:RwMain.java

示例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();
    }
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:9,代碼來源:RwMain.java

示例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();
    }
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:9,代碼來源:RwMain.java

示例10: toString

import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
/**
 * To JSON string.
 */
@Override
public String toString() {
    return JSONArray.toJSONString(this);
}
 
開發者ID:czp3009,項目名稱:bilibili-live-api,代碼行數:8,代碼來源:DanMuResponseEntity.java

示例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;
}
 
開發者ID:majinju,項目名稱:KettleEasyExpand,代碼行數:68,代碼來源:DataValidate.java


注:本文中的com.alibaba.fastjson.JSONArray.toJSONString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。