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


Java JSON.toString方法代碼示例

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


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

示例1: executeJsonPost

import net.sf.json.JSON; //導入方法依賴的package包/類
public String executeJsonPost(String url, JSON jsonObj) throws ParseException, IOException
{
    if(url.startsWith("/"))
    {
        url = host + url;
    }
    
    HttpPost post = new HttpPost(url);
    
    StringEntity entity = new StringEntity(jsonObj.toString(), HTTP.UTF_8);
    entity.setContentType("application/json");
    
    post.setEntity(entity);
    
    return fetchReponseText(post);
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.interface.framework,代碼行數:17,代碼來源:SimpleHttpClient.java

示例2: createMetadataObject

import net.sf.json.JSON; //導入方法依賴的package包/類
/**
 * Creates a new object in the metadata server
 *
 * @param projectId project id (hash)
 * @param content   the new object content
 * @return the new object
 */
public JSONObject createMetadataObject(String projectId, JSON content) {
    l.debug("Executing createMetadataObject on project id=" + projectId + "content='" + content.toString() + "'");
    PostMethod req = createPostMethod(getProjectMdUrl(projectId) + OBJ_URI + "?createAndGet=true");
    try {
        String str = content.toString();
        InputStreamRequestEntity request = new InputStreamRequestEntity(new ByteArrayInputStream(str.getBytes("utf-8")));
        req.setRequestEntity(request);
        String resp = executeMethodOk(req);
        JSONObject parsedResp = JSONObject.fromObject(resp);
        return parsedResp;
    } catch (HttpMethodException ex) {
        l.debug("Failed executing createMetadataObject on project id=" + projectId + "content='" + content.toString() + "'");
        throw new GdcRestApiException("Failed executing createMetadataObject on project id=" + projectId + "content='" + content.toString() + "'", ex);
    } catch (UnsupportedEncodingException e) {
        l.debug("String#getBytes(\"utf-8\") threw UnsupportedEncodingException", e);
        throw new IllegalStateException(e);
    } finally {
        req.releaseConnection();
    }
}
 
開發者ID:koles,項目名稱:gooddata-agent,代碼行數:28,代碼來源:GdcRESTApiWrapper.java

示例3: modifyMetadataObject

import net.sf.json.JSON; //導入方法依賴的package包/類
/**
 * Modifies an object in the metadata server
 *
 * @param uri     object uri
 * @param content the new object content
 * @return the new object
 */
public JSONObject modifyMetadataObject(String uri, JSON content) {
    l.debug("Executing modifyMetadataObject on uri=" + uri + " content='" + content.toString() + "'");
    PostMethod req = createPostMethod(getServerUrl() + uri);
    try {
        InputStreamRequestEntity request = new InputStreamRequestEntity(new ByteArrayInputStream(
                content.toString().getBytes("utf-8")));
        req.setRequestEntity(request);
        String resp = executeMethodOk(req);
        JSONObject parsedResp = JSONObject.fromObject(resp);
        return parsedResp;
    } catch (HttpMethodException ex) {
        l.debug("Failed executing modifyMetadataObject on uri=" + uri + " content='" + content.toString() + "'");
        throw new GdcRestApiException("Failed executing modifyMetadataObject on uri=" + uri + " content='" + content.toString() + "'", ex);
    } catch (UnsupportedEncodingException e) {
        l.debug("String#getBytes(\"utf-8\") threw UnsupportedEncodingException", e);
        throw new IllegalStateException(e);
    } finally {
        req.releaseConnection();
    }
}
 
開發者ID:koles,項目名稱:gooddata-agent,代碼行數:28,代碼來源:GdcRESTApiWrapper.java

示例4: createPatch

import net.sf.json.JSON; //導入方法依賴的package包/類
/**
 * Create Patch Request
 */
public HttpPatch createPatch(String url, JSON data) {
    HttpPatch patch = new HttpPatch(url);
    patch.setHeader("Content-Type", "application/json");

    String string = data.toString(1);
    try {
        patch.setEntity(new StringEntity(string, "UTF-8"));
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
    return patch;
}
 
開發者ID:Blazemeter,項目名稱:jmeter-bzm-plugins,代碼行數:16,代碼來源:HttpUtils.java

示例5: toString

import net.sf.json.JSON; //導入方法依賴的package包/類
/**
 * rows 列表中的數據格式化成json格式   不同與toJSON
 * map.put("type", "list");
   	map.put("result", result);
   	map.put("message", message);
   	map.put("rows", rows);
   	map.put("success", result);
   	map.put("navi", navi);
 */
public String toString() {
	Map<String,Object> map = new HashMap<String,Object>();
   	map.put("type", "list");
   	map.put("result", result);
   	map.put("message", message);
   	map.put("rows", rows);
   	map.put("success", result);
   	map.put("navi", navi);
   	JSON json = JSONObject.fromObject(map);
	return json.toString();
}
 
開發者ID:anylineorg,項目名稱:anyline,代碼行數:21,代碼來源:DataSet.java

示例6: loadObjectsFromXmlFiles

import net.sf.json.JSON; //導入方法依賴的package包/類
private static void loadObjectsFromXmlFiles(Scriptable scope, Map<String, File> maps)
{
    // JsonParser jsonp = new JsonParser(cx, scope);
    for (String varname : maps.keySet()) {
        File file = maps.get(varname);
        JSON json = XmlToJsonConverter.getJsonFromXmlFile(file);
        scope.put(varname, scope, json);
        String element = json.toString();
        scope.put("_" + varname + "_", scope, element);
        continue;
    }
    return;
}
 
開發者ID:gmrodrigues,項目名稱:JsSandbox,代碼行數:14,代碼來源:JsSandboxEvaluators.java

示例7: getTotalAssignToListJSON

import net.sf.json.JSON; //導入方法依賴的package包/類
public String getTotalAssignToListJSON() {
	if (this.courseMemberMap == null) {
		this.courseMemberMap = membershipManager.getFilteredCourseMembers(true, null);
	}
	List members = membershipManager.convertMemberMapToList(courseMemberMap);
	List jsonList = transformItemList(members);
	JsonConfig config = new JsonConfig();
	JSON json = JSONSerializer.toJSON(jsonList);
	if (log.isDebugEnabled()) log.debug(" finished getTotalAssignToListJSON");
	return json.toString(4, 0);
}
 
開發者ID:sakaiproject,項目名稱:sakai,代碼行數:12,代碼來源:DiscussionForumTool.java

示例8: testSimpleResourceEncode

import net.sf.json.JSON; //導入方法依賴的package包/類
@Test
public void testSimpleResourceEncode() throws IOException {

	String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8"));
	Patient obs = ourCtx.newXmlParser().parseResource(Patient.class, xmlString);

	List<ExtensionDt> undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions();
	ExtensionDt undeclaredExtension = undeclaredExtensions.get(0);
	assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl());

	ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToWriter(obs, new OutputStreamWriter(System.out));

	IParser jsonParser = ourCtx.newJsonParser();
	String encoded = jsonParser.encodeResourceToString(obs);
	ourLog.info(encoded);

	String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8"));

	JSON expected = JSONSerializer.toJSON(jsonString);
	JSON actual = JSONSerializer.toJSON(encoded.trim());

	// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
	String exp = expected.toString().replace("\\\"Jim\\\"", "&quot;Jim&quot;");
	String act = actual.toString();

	ourLog.info("Expected: {}", exp);
	ourLog.info("Actual  : {}", act);
	assertEquals(exp, act);

}
 
開發者ID:gajen0981,項目名稱:FHIR-Server,代碼行數:31,代碼來源:JsonParserTest.java

示例9: testSimpleResourceEncodeWithCustomType

import net.sf.json.JSON; //導入方法依賴的package包/類
@Test
public void testSimpleResourceEncodeWithCustomType() throws IOException {

	FhirContext fhirCtx = new FhirContext(MyPatientWithExtensions.class);
	String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8"));
	MyPatientWithExtensions obs = fhirCtx.newXmlParser().parseResource(MyPatientWithExtensions.class, xmlString);

	assertEquals(0, obs.getAllUndeclaredExtensions().size());
	assertEquals("aaaa", obs.getExtAtt().getContentType().getValue());
	assertEquals("str1", obs.getMoreExt().getStr1().getValue());
	assertEquals("2011-01-02", obs.getModExt().getValueAsString());

	List<ExtensionDt> undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions();
	ExtensionDt undeclaredExtension = undeclaredExtensions.get(0);
	assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl());

	IParser jsonParser = fhirCtx.newJsonParser().setPrettyPrint(true);
	String encoded = jsonParser.encodeResourceToString(obs);
	ourLog.info(encoded);

	String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8"));

	JSON expected = JSONSerializer.toJSON(jsonString);
	JSON actual = JSONSerializer.toJSON(encoded.trim());

	// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
	String exp = expected.toString().replace("\\\"Jim\\\"", "&quot;Jim&quot;");
	String act = actual.toString();

	ourLog.info("Expected: {}", exp);
	ourLog.info("Actual  : {}", act);
	assertEquals(exp, act);

}
 
開發者ID:gajen0981,項目名稱:FHIR-Server,代碼行數:35,代碼來源:JsonParserTest.java

示例10: testSimpleResourceEncode

import net.sf.json.JSON; //導入方法依賴的package包/類
@Test
public void testSimpleResourceEncode() throws IOException {

	String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8"));
	Patient obs = ourCtx.newXmlParser().parseResource(Patient.class, xmlString);

	List<Extension> undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getExtension();
	Extension undeclaredExtension = undeclaredExtensions.get(0);
	assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl());

	ourLog.info(ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(obs));

	IParser jsonParser = ourCtx.newJsonParser();
	String encoded = jsonParser.encodeResourceToString(obs);
	ourLog.info(encoded);

	String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8"));

	JSON expected = JSONSerializer.toJSON(jsonString);
	JSON actual = JSONSerializer.toJSON(encoded.trim());

	// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
	String exp = expected.toString().replace("\\\"Jim\\\"", "&quot;Jim&quot;");
	String act = actual.toString();

	ourLog.info("Expected: {}", exp);
	ourLog.info("Actual  : {}", act);
	assertEquals(exp, act);

}
 
開發者ID:gajen0981,項目名稱:FHIR-Server,代碼行數:31,代碼來源:JsonParserTest.java

示例11: testSimpleResourceEncodeWithCustomType

import net.sf.json.JSON; //導入方法依賴的package包/類
@Test
public void testSimpleResourceEncodeWithCustomType() throws IOException {

	FhirContext fhirCtx = new FhirContext(MyObservationWithExtensions.class);
	String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8"));
	MyObservationWithExtensions obs = fhirCtx.newXmlParser().parseResource(MyObservationWithExtensions.class, xmlString);

	assertEquals(0, obs.getExtension().size());
	assertEquals("aaaa", obs.getExtAtt().getContentType());
	assertEquals("str1", obs.getMoreExt().getStr1().getValue());
	assertEquals("2011-01-02", obs.getModExt().getValueAsString());

	List<Extension> undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getExtension();
	Extension undeclaredExtension = undeclaredExtensions.get(0);
	assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl());

	IParser jsonParser = fhirCtx.newJsonParser().setPrettyPrint(true);
	String encoded = jsonParser.encodeResourceToString(obs);
	ourLog.info(encoded);

	String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8"));

	JSON expected = JSONSerializer.toJSON(jsonString);
	JSON actual = JSONSerializer.toJSON(encoded.trim());

	// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
	String exp = expected.toString().replace("\\\"Jim\\\"", "&quot;Jim&quot;");
	String act = actual.toString();

	ourLog.info("Expected: {}", exp);
	ourLog.info("Actual  : {}", act);
	assertEquals(exp, act);

}
 
開發者ID:gajen0981,項目名稱:FHIR-Server,代碼行數:35,代碼來源:JsonParserTest.java

示例12: ConvertXMLtoJSON

import net.sf.json.JSON; //導入方法依賴的package包/類
public static String ConvertXMLtoJSON(String xml)  {  
	XMLSerializer xmlSerializer = new XMLSerializer();  
	JSON json =null;
	  
       json = xmlSerializer.read(xml);  
	return json.toString(1);  
}
 
開發者ID:apicloudcom,項目名稱:APICloud-Studio,代碼行數:8,代碼來源:Feature.java

示例13: testJsonLikeSimpleResourceEncode

import net.sf.json.JSON; //導入方法依賴的package包/類
@Test
public void testJsonLikeSimpleResourceEncode() throws IOException {

	String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8"));
	IParser parser = ourCtx.newXmlParser();
	parser.setParserErrorHandler(new StrictErrorHandler());
	Patient obs = parser.parseResource(Patient.class, xmlString);

	IJsonLikeParser jsonLikeParser = (IJsonLikeParser)ourCtx.newJsonParser();
	StringWriter stringWriter = new StringWriter();
	JsonLikeStructure jsonLikeStructure = new GsonStructure();
	JsonLikeWriter jsonLikeWriter = jsonLikeStructure.getJsonLikeWriter(stringWriter);
	jsonLikeParser.encodeResourceToJsonLikeWriter(obs, jsonLikeWriter);
	String encoded = stringWriter.toString();
	ourLog.info(encoded);

	String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8"));

	JSON expected = JSONSerializer.toJSON(jsonString);
	JSON actual = JSONSerializer.toJSON(encoded.trim());

	// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
	String exp = expected.toString().replace("\\\"Jim\\\"", "&quot;Jim&quot;");
	String act = actual.toString();

	ourLog.info("Expected: {}", exp);
	ourLog.info("Actual  : {}", act);
	assertEquals("\nExpected: " + exp + "\nActual  : " + act, exp, act);

}
 
開發者ID:jamesagnew,項目名稱:hapi-fhir,代碼行數:31,代碼來源:JsonLikeParserTest.java

示例14: testSimpleResourceEncode

import net.sf.json.JSON; //導入方法依賴的package包/類
@Test
public void testSimpleResourceEncode() throws IOException {

	String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8"));
	IParser parser = ourCtx.newXmlParser();
	parser.setParserErrorHandler(new StrictErrorHandler());
	Patient obs = parser.parseResource(Patient.class, xmlString);

	List<ExtensionDt> undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions();
	ExtensionDt undeclaredExtension = undeclaredExtensions.get(0);
	assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl());
	assertEquals("VV", ((CodeDt)undeclaredExtension.getValue()).getValue());

	ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToWriter(obs, new OutputStreamWriter(System.out));

	IParser jsonParser = ourCtx.newJsonParser();
	String encoded = jsonParser.encodeResourceToString(obs);
	ourLog.info(encoded);

	String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8"));

	JSON expected = JSONSerializer.toJSON(jsonString);
	JSON actual = JSONSerializer.toJSON(encoded.trim());

	// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
	String exp = expected.toString().replace("\\\"Jim\\\"", "&quot;Jim&quot;");
	String act = actual.toString();

	ourLog.info("Expected: {}", exp);
	ourLog.info("Actual  : {}", act);
	assertEquals("\nExpected: " + exp + "\nActual  : " + act, exp, act);

}
 
開發者ID:jamesagnew,項目名稱:hapi-fhir,代碼行數:34,代碼來源:JsonParserTest.java

示例15: testSimpleResourceEncodeWithCustomType

import net.sf.json.JSON; //導入方法依賴的package包/類
@Test
public void testSimpleResourceEncodeWithCustomType() throws IOException {

	FhirContext fhirCtx = new FhirContext(MyPatientWithExtensions.class);
	String xmlString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.xml"), Charset.forName("UTF-8"));
	MyPatientWithExtensions obs = fhirCtx.newXmlParser().parseResource(MyPatientWithExtensions.class, xmlString);

	assertEquals(0, obs.getAllUndeclaredExtensions().size());
	assertEquals("aaaa", obs.getExtAtt().getContentType().getValue());
	assertEquals("str1", obs.getMoreExt().getStr1().getValue());
	assertEquals("2011-01-02", obs.getModExt().getValueAsString());

	List<ExtensionDt> undeclaredExtensions = obs.getContact().get(0).getName().getFamily().get(0).getUndeclaredExtensions();
	ExtensionDt undeclaredExtension = undeclaredExtensions.get(0);
	assertEquals("http://hl7.org/fhir/Profile/iso-21090#qualifier", undeclaredExtension.getUrl());

	IParser jsonParser = fhirCtx.newJsonParser().setPrettyPrint(true);
	String encoded = jsonParser.encodeResourceToString(obs);
	ourLog.info(encoded);

	String jsonString = IOUtils.toString(JsonParser.class.getResourceAsStream("/example-patient-general.json"), Charset.forName("UTF-8"));

	JSON expected = JSONSerializer.toJSON(jsonString);
	JSON actual = JSONSerializer.toJSON(encoded.trim());

	// The encoded escapes quote marks using XML escaping instead of JSON escaping, which is probably nicer anyhow...
	String exp = expected.toString().replace("\\\"Jim\\\"", "&quot;Jim&quot;");
	String act = actual.toString();

	ourLog.info("Expected: {}", exp);
	ourLog.info("Actual  : {}", act);
	assertEquals("\nExpected: " + exp + "\nActual  : " + act, exp, act);
}
 
開發者ID:jamesagnew,項目名稱:hapi-fhir,代碼行數:34,代碼來源:JsonParserTest.java


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