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


Java JSONSerializer類代碼示例

本文整理匯總了Java中net.sf.json.JSONSerializer的典型用法代碼示例。如果您正苦於以下問題:Java JSONSerializer類的具體用法?Java JSONSerializer怎麽用?Java JSONSerializer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JSONSerializer類屬於net.sf.json包,在下文中一共展示了JSONSerializer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractErrorMessage

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Override
protected String extractErrorMessage(String response) {
    if (response != null && !response.isEmpty()) {
        try {
            JSON jsonResponse = JSONSerializer.toJSON(response, new JsonConfig());
            if (jsonResponse instanceof JSONObject) {
                JSONObject object = (JSONObject) jsonResponse;
                JSONObject errorObj = object.getJSONObject("error");
                if (errorObj.containsKey("message")) {
                    return errorObj.getString("message");
                }
            }
        } catch (JSONException ex) {
            log.debug("Cannot parse JSON error response: " + response);
        }
    }
    return response;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:19,代碼來源:BlazeMeterHttpUtils.java

示例2: jsonToLimitViolation

import net.sf.json.JSONSerializer; //導入依賴的package包/類
public static LimitViolation jsonToLimitViolation(String json, Network network) {
    JSONObject jsonObj = (JSONObject) JSONSerializer.toJSON(json);
    Map<String, String> limitViolation = (Map<String, String>) JSONObject.toBean(jsonObj, Map.class);
    Country country = null;
    if (limitViolation.containsKey("Country")) {
        country = Country.valueOf(limitViolation.get("Country"));
    }
    float baseVoltage = Float.NaN;
    if (limitViolation.containsKey("BaseVoltage")) {
        baseVoltage = Float.parseFloat(limitViolation.get("BaseVoltage"));
    }
    float limitReduction = 1f;
    if (limitViolation.containsKey("LimitReduction")) {
        limitReduction = Float.parseFloat(limitViolation.get("LimitReduction"));
    }
    return new LimitViolation(limitViolation.get("Subject"),
            LimitViolationType.valueOf(limitViolation.get("LimitType")),
            Float.parseFloat(limitViolation.get("Limit")),
            limitViolation.get("LimitName"),
            limitReduction,
            Float.parseFloat(limitViolation.get("Value")),
            country,
            baseVoltage);
}
 
開發者ID:itesla,項目名稱:ipst,代碼行數:25,代碼來源:OnlineDbMVStoreUtils.java

示例3: checkForDx

import net.sf.json.JSONSerializer; //導入依賴的package包/類
public ActionForward checkForDx(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
	String demographicNo = request.getParameter("demographicNo");
	String codingSystem = request.getParameter("codingSystem");
	String code = request.getParameter("code");
	
	boolean exists = dxResearchDao.activeEntryExists(Integer.parseInt(demographicNo), codingSystem, code);
	
	String str = "{'result':"+exists+"}";  
	JSONObject jsonArray = (JSONObject) JSONSerializer.toJSON(str);
       response.setContentType("text/x-json");
       try {
       	jsonArray.write(response.getWriter());
       }catch(IOException e) {
       	MiscUtils.getLogger().error("Error",e);
       }

	return null;
}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:19,代碼來源:RenalAction.java

示例4: unspecified

import net.sf.json.JSONSerializer; //導入依賴的package包/類
public ActionForward unspecified(ActionMapping mapping, ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
    String searchStr=request.getParameter("providerKeyword");
    if(searchStr==null){
        searchStr=request.getParameter("query");
    }
    if(searchStr==null){
        searchStr=request.getParameter("name");
    }        
   
    
    MiscUtils.getLogger().info("Search Provider " + searchStr);
    List provList=ProviderData.searchProvider(searchStr,true);
    Hashtable d=new Hashtable();
    d.put("results", provList);

    response.setContentType("text/x-json");
    JSONObject jsonArray=(JSONObject) JSONSerializer.toJSON(d);
    jsonArray.write(response.getWriter());
    return null;

}
 
開發者ID:williamgrosset,項目名稱:OSCAR-ConCert,代碼行數:22,代碼來源:SearchProviderAutoCompleteAction.java

示例5: createWebHook

import net.sf.json.JSONSerializer; //導入依賴的package包/類
/**
 * Creates a web hook in Gogs with the passed json configuration string
 *
 * @param jsonCommand A json buffer with the creation command of the web hook
 * @param projectName the project (owned by the user) where the webHook should be created
 * @throws IOException something went wrong
 */
int createWebHook(String jsonCommand, String projectName) throws IOException {

    String gogsHooksConfigUrl = getGogsServer_apiUrl()
            + "repos/" + this.gogsServer_user
            + "/" + projectName + "/hooks";

    Executor executor = getExecutor();

    String result = executor
            .execute(Request.Post(gogsHooksConfigUrl).bodyString(jsonCommand, ContentType.APPLICATION_JSON))
            .returnContent().asString();
    JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( result );
    int id = jsonObject.getInt("id");

    return id;
}
 
開發者ID:jenkinsci,項目名稱:gogs-webhook-plugin,代碼行數:24,代碼來源:GogsConfigHandler.java

示例6: isSourceArrayValid

import net.sf.json.JSONSerializer; //導入依賴的package包/類
/**
 * Validates the request parameter sourceArray
 *
 * @param sourceArray The request parameter sourceArray
 * @return true if validated
 */
private boolean isSourceArrayValid(String sourceArray) {
    JSONArray sourceJSON;
    try {
        sourceJSON = (JSONArray) JSONSerializer.toJSON(sourceArray);
    } catch (JSONException ex) {
        logger.error("JSONException : " + ex);
        return false;
    }
    if (!prepareLists(sourceJSON)) {
        throw new OperationFailedException("The requested resource(s) do not exist in the " + "repository. " +
                "Aborting operation.");
    }
    extensionsList = getListOfExtensionsFromSettings();
    return (extensionsList != null);
}
 
開發者ID:helicalinsight,項目名稱:helicalinsight,代碼行數:22,代碼來源:DeleteOperationHandler.java

示例7: setRequestData

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Override
public void setRequestData(String data) {
    requestParameterJson = (JSONObject) JSONSerializer.toJSON(data);
    String downloadType = requestParameterJson.optString("type");
    // Set the content type for the response from the properties file
    this.contentType = (propertyMap.get(downloadType));

    if (downloadType == null || downloadType.isEmpty()) {
        //Default type being csv format
        this.fileExtension = ".csv";
        downloadType = "csv";
    } else {
        this.fileExtension = "." + downloadType;
    }

    String beanName = settingsDownloadMap.get(downloadType);
    iDownload = (IDownload) ApplicationContextAccessor.getBean(beanName);
    CacheManager = this.getCacheManager();
    CacheManager.setRequestData(data);
}
 
開發者ID:helicalinsight,項目名稱:helicalinsight,代碼行數:21,代碼來源:DownloadCacheManager.java

示例8: testMarshalAndUnmarshal

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Test
public void testMarshalAndUnmarshal() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    MockEndpoint mockXML = getMockEndpoint("mock:xml");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);

    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());

    template.sendBody("direct:unmarshal", jsonString);

    mockJSON.assertIsSatisfied();
    mockXML.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:SpringXmlJsonDataFormatTest.java

示例9: testSomeOptionsToJSON

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Test
public void testSomeOptionsToJSON() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSON must contain 1 top-level element", 1, obj.entrySet().size());
    assertTrue("Top-level element must be named root", obj.has("root"));

    mockJSON.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:XmlJsonOptionsTest.java

示例10: testXmlWithTypeAttributesToJSON

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Test
public void testXmlWithTypeAttributesToJSON() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage4.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSON must contain 1 top-level element", 1, obj.entrySet().size());
    assertTrue("Top-level element must be named root", obj.has("root"));

    mockJSON.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:XmlJsonOptionsTest.java

示例11: testNamespacesDropped

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Test
public void testNamespacesDropped() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage2-namespaces.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSON must contain 1 top-level element", 1, obj.entrySet().size());
    assertTrue("Top-level element must be named root", obj.has("root"));
    // check that no child of the top-level element has a colon in its key,
    // which would denote that
    // a namespace prefix exists
    for (Object key : obj.getJSONObject("root").keySet()) {
        assertFalse("A key contains a colon", ((String) key).contains(":"));
    }

    mockJSON.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:XmlJsonOptionsTest.java

示例12: testTypeHintsToJSON

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Test
public void testTypeHintsToJSON() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage5-typeHints.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:jsonTypeHints");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshalTypeHints", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("root.a must be number", Integer.valueOf(1), obj.getJSONObject("root").get("a"));
    assertEquals("root.b must be boolean", Boolean.TRUE, obj.getJSONObject("root").get("b"));

    mockJSON.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:XmlJsonOptionsTest.java

示例13: testPrefixedTypeHintsToJSON

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Test
public void testPrefixedTypeHintsToJSON() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage6-prefixedTypeHints.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:jsonPrefixedTypeHints");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshalPrefixedTypeHints", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("root.a must be number", Integer.valueOf(1), obj.getJSONObject("root").get("a"));
    assertEquals("root.b must be boolean", Boolean.TRUE, obj.getJSONObject("root").get("b"));

    mockJSON.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:18,代碼來源:XmlJsonOptionsTest.java

示例14: testUnmarshalJSONObject

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Test
public void testUnmarshalJSONObject() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.json");
    String in = context.getTypeConverter().convertTo(String.class, inStream);
    JSON json = JSONSerializer.toJSON(in);

    MockEndpoint mockXML = getMockEndpoint("mock:xml");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);

    Object marshalled = template.requestBody("direct:unmarshal", json);
    Document document = context.getTypeConverter().convertTo(Document.class, marshalled);
    assertEquals("The XML document has an unexpected root node", "o", document.getDocumentElement().getLocalName());

    mockXML.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:17,代碼來源:XmlJsonDataFormatTest.java

示例15: testMarshalAndUnmarshalInline

import net.sf.json.JSONSerializer; //導入依賴的package包/類
@Test
public void testMarshalAndUnmarshalInline() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:jsonInline");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    MockEndpoint mockXML = getMockEndpoint("mock:xmlInline");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);

    Object json = template.requestBody("direct:marshalInline", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());

    template.sendBody("direct:unmarshalInline", jsonString);

    mockJSON.assertIsSatisfied();
    mockXML.assertIsSatisfied();
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:24,代碼來源:XmlJsonDataFormatTest.java


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