当前位置: 首页>>代码示例>>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;未经允许,请勿转载。