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


Java Json.toJsonString方法代碼示例

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


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

示例1: asJsonString

import org.ojai.json.Json; //導入方法依賴的package包/類
@Override
public String asJsonString(JsonOptions options) {
  return Json.toJsonString(this, options);
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:5,代碼來源:JsonDocument.java

示例2: asJsonString

import org.ojai.json.Json; //導入方法依賴的package包/類
@Override
public String asJsonString() {
  return Json.toJsonString(asReader(), JsonOptions.WITH_TAGS);
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:5,代碼來源:JsonValue.java

示例3: testJson_NewDocument

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testJson_NewDocument() {
  Document doc = Json.newDocument("{}");
  assertTrue(doc.size() == 0);

  doc = Json.newDocument(
      "{\n" +
      "  \"business_id\": \"vcNAWiLM4dR7D2nwwJ7nCA\",\n" +
      "  \"full_address\": \"4840 E Indian School Rd\\nSte 101\\nPhoenix, AZ 85018\",\n" +
      "  \"hours\": {\n" +
      "    \"Tuesday\": {\n" +
      "      \"close\": \"17:00\",\n" +
      "      \"open\": \"08:00\"\n" +
      "    },\n" +
      "    \"Friday\": {\n" +
      "      \"close\": \"17:00\",\n" +
      "      \"open\": \"08:00\"\n" +
      "    },\n" +
      "    \"Monday\": {\n" +
      "      \"close\": \"17:00\",\n" +
      "      \"open\": \"08:00\"\n" +
      "    },\n" +
      "    \"Wednesday\": {\n" +
      "      \"close\": \"17:00\",\n" +
      "      \"open\": \"08:00\"\n" +
      "    },\n" +
      "    \"Thursday\": {\n" +
      "      \"close\": \"17:00\",\n" +
      "      \"open\": \"08:00\"\n" +
      "    }\n" +
      "  },\n" +
      "  \"open\": true,\n" +
      "  \"categories\": [\"Doctors\",\n" +
      "  \"Health & Medical\"],\n" +
      "  \"city\": \"Phoenix\",\n" +
      "  \"review_count\": 7,\n" +
      "  \"name\": \"Eric Goldberg, MD\",\n" +
      "  \"neighborhoods\": [],\n" +
      "  \"longitude\": -111,\n" +
      "  \"state\": \"AZ\",\n" +
      "  \"stars\": 3.5,\n" +
      "  \"latitude\": 33.499313000000001,\n" +
      "  \"attributes\": {\n" +
      "    \"By Appointment Only\": true\n" +
      "  },\n" +
      "  \"type\": \"business\"\n" +
      "}");
  assertEquals(15, doc.size());
  assertEquals("08:00", doc.getString("hours.Wednesday.open"));
  assertEquals("Health & Medical", doc.getString("categories[1]"));

  String jsonString = Json.toJsonString(doc.asReader());
  Pattern p1 = Pattern.compile(".*\"review_count\".*:.*7,.*", Pattern.DOTALL);
  Pattern p2 = Pattern.compile(".*\"longitude\".*:.*-111,.*", Pattern.DOTALL);
  assertTrue(p1.matcher(jsonString).matches());
  assertTrue(p2.matcher(jsonString).matches());
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:58,代碼來源:TestJson.java

示例4: testJson_AsJsonStringComplex

import org.ojai.json.Json; //導入方法依賴的package包/類
@Test
public void testJson_AsJsonStringComplex() throws Exception {
  try (InputStream in = getJsonStream("org/ojai/test/data/complex.json");
       DocumentStream stream = Json.newDocumentStream(in)) {
    Document doc = stream.iterator().next();
    String s = Json.toJsonString(doc);
    assertEquals("{\"first\":\"Sam\",\"last\":\"LNU\",\"age\":23,\"sex\":\"F\",\"salary\":315000,"
        + "\"active\":true,\"interests\":[\"Reading\",\"Hiking\",{\"passive\":[\"sleeping\","
        + "\"dreaming\"]}],\"favorites\":{\"color\":\"Red\",\"sport\":\"Cricket\","
        + "\"food\":\"Nasi Goreng\"},\"skills\":[{\"category\":\"Economics\","
        + "\"tests\":[{\"name\":\"ECO101\",\"score\":90},{\"name\":\"ECO212\",\"score\":96},"
        + "[\"ECO152\",87,\"ECO162\",91]]},{\"category\":\"Computer Science\","
        + "\"tests\":[{\"name\":\"CS404\",\"score\":99},{\"name\":\"CS301\",\"score\":93}]}]}", s);

    s = Json.toJsonString(doc, new JsonOptions().pretty());
    assertEquals("{\n" +
        "  \"first\" : \"Sam\",\n" +
        "  \"last\" : \"LNU\",\n" +
        "  \"age\" : 23,\n" +
        "  \"sex\" : \"F\",\n" +
        "  \"salary\" : 315000,\n" +
        "  \"active\" : true,\n" +
        "  \"interests\" : [ \"Reading\", \"Hiking\", {\n" +
        "    \"passive\" : [ \"sleeping\", \"dreaming\" ]\n" +
        "  } ],\n" +
        "  \"favorites\" : {\n" +
        "    \"color\" : \"Red\",\n" +
        "    \"sport\" : \"Cricket\",\n" +
        "    \"food\" : \"Nasi Goreng\"\n" +
        "  },\n" +
        "  \"skills\" : [ {\n" +
        "    \"category\" : \"Economics\",\n" +
        "    \"tests\" : [ {\n" +
        "      \"name\" : \"ECO101\",\n" +
        "      \"score\" : 90\n" +
        "    }, {\n" +
        "      \"name\" : \"ECO212\",\n" +
        "      \"score\" : 96\n" +
        "    }, [ \"ECO152\", 87, \"ECO162\", 91 ] ]\n" +
        "  }, {\n" +
        "    \"category\" : \"Computer Science\",\n" +
        "    \"tests\" : [ {\n" +
        "      \"name\" : \"CS404\",\n" +
        "      \"score\" : 99\n" +
        "    }, {\n" +
        "      \"name\" : \"CS301\",\n" +
        "      \"score\" : 93\n" +
        "    } ]\n" +
        "  } ]\n" +
        "}", s);
  }
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:53,代碼來源:TestJson.java

示例5: asJsonString

import org.ojai.json.Json; //導入方法依賴的package包/類
/**
 * Converts a {@code Value} to its extended JSON representation.<br/><br/>
 * The 7 intrinsic types, &nbsp;{@code null, boolean, string, long,
 * double, array, and map }, are represented in regular JSON. The
 * extended types are converted to a singleton map with the type tag name
 * as the key and the value of the given {@code Value} as its value.
 * The following sample illustrates the string representation of the
 * various types.
 *
 * <pre>
 * {
 *   "map": {
 *     "null": null,
 *     "boolean" : true,
 *     "string": "eureka",
 *     "byte" : {"$numberLong": 127},
 *     "short": {"$numberLong": 32767},
 *     "int": {"$numberLong": 2147483647},
 *     "long": {"$numberLong":9223372036854775807},
 *     "float" : 3.4028235E38,
 *     "double" : 1.7976931348623157e308,
 *     "decimal": {"$decimal": "12345678901234567890189012345678901.23456789"},
 *     "date": {"$dateDay": "&lt;yyyy-mm-dd&gt;"},
 *     "time" : {"$time" : "&lt;HH:mm:ss[.sss]&gt;"},
 *     "timestamp" : {"$date" : "&lt;yyyy-MM-ddTHH:mm:ss.SSSXXX&gt;"},
 *     "interval" : {"$interval" : &lt;number_of_millisecods&gt;},
 *     "binary" : {"$binary" : "&lt;base64_encoded_binary_value&gt;"},
 *     "array" : [42, "open sesame", 3.14, {"$dateDay": "2015-01-21"}]
 *   }
 * }
 * </pre>
 *
 * @param value a <code>Value</code> that should be converted to JSON string
 * @return The extended JSON representation of the given value
 */
public static String asJsonString(@NonNullable Value value) {
  return Json.toJsonString(value.asReader(), JsonOptions.WITH_TAGS);
}
 
開發者ID:ojai,項目名稱:ojai,代碼行數:39,代碼來源:Values.java


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