本文整理汇总了Scala中scala.util.parsing.json.JSONObject类的典型用法代码示例。如果您正苦于以下问题:Scala JSONObject类的具体用法?Scala JSONObject怎么用?Scala JSONObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSONObject类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: OneThousandLabeledNodesTest
//设置package包名称以及导入依赖的类
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.parsing.json.{JSONObject, JSONArray}
class OneThousandLabeledNodesTest extends Simulation {
val httpConf = http
.baseURL("http://localhost:7474")
.acceptHeader("application/json")
.shareConnections
// Uncomment to see the response of each request.
// .extraInfoExtractor(extraInfo => {
// println(extraInfo.response.body.string)
// Nil
// }).disableResponseChunksDiscarding
val random = new util.Random
val cypher = """CREATE ( me:User { user_id: {user_id} } )"""
val oneThousand = JSONArray.apply(
List.fill(1000)(
JSONObject.apply(
Map("statement" -> cypher,
"parameters" -> JSONObject.apply(
Map("user_id" -> random.nextInt())))
)
)
)
val statements = JSONObject.apply(Map("statements" -> oneThousand))
val scn = scenario("Create 1000 Labeled Nodes")
.during(30 seconds) {
exec(
http("create 1000 labeled nodes")
.post("/db/data/transaction/commit")
.basicAuth("neo4j", "swordfish")
.body(StringBody(statements.toString()))
.asJSON
.check(status.is(200))
)
}
setUp(
scn.inject( atOnceUsers(8) ).protocols(httpConf)
)
}
示例2: MsgWrapper
//设置package包名称以及导入依赖的类
package com.asto.dmp.alipay.mq
import scala.util.parsing.json.{JSONArray, JSONObject}
object MsgWrapper {
def getJson(majorBusiness: String, msgList: List[Msg]): String = {
new JSONObject(Map(
"majorBusiness" -> majorBusiness,
"quotaItemList" -> JSONArray(for (msg <- msgList) yield toJsonObj(msg))
)).toString()
}
def getJson(majorBusiness: String, msgs: Msg *): String = {
getJson(majorBusiness: String, msgs.toList)
}
def toJsonObj(msg: Msg): JSONObject = {
new JSONObject(Map[String, Any]("indexFlag" -> msg.indexFlag, "quotaCode" -> msg.quotaCode,"quotaValue" -> msg.quotaValue, "targetTime" -> msg.targetTime, "quotaName" -> msg.quotaName))
}
}
class Msg(val quotaCode: String, val quotaValue: Any, val targetTime: String , val indexFlag: String = "2", val quotaName: String = "")
示例3: PartyRelWrapper
//设置package包名称以及导入依赖的类
package com.asto.dmp.relcir.mq
import scala.util.parsing.json.{JSONArray, JSONObject}
object PartyRelWrapper {
def getJsonStr(msgList: List[PartyRelMsg]): String = {
new JSONObject(Map(
"partyRelList" -> JSONArray(for (msg <- msgList) yield toJsonObj(msg))
)).toString()
}
def toJsonObj(msg: PartyRelMsg): JSONObject = {
new JSONObject(Map[String, Any]("partyRelGroupId" -> msg.partyRelGroupId, "fromPartyUuid" -> msg.fromPartyUuid, "toPartyUuid" -> msg.toPartyUuid))
}
}
case class PartyRelMsg(val partyRelGroupId: String, val fromPartyUuid: String, val toPartyUuid: String)
示例4: RelWrapper
//设置package包名称以及导入依赖的类
package com.asto.dmp.relcir.mq
import scala.util.parsing.json.{JSONArray, JSONObject}
object RelWrapper {
def getJsonStr(msgList: List[RelMsg]): String = {
new JSONObject(Map(
"relList" -> JSONArray(for (msg <- msgList) yield toJsonObj(msg))
)).toString()
}
def toJsonObj(msg: RelMsg): JSONObject = {
new JSONObject(Map[String, Any]("partyRelGroupId" -> msg.partyRelGroupId, "partyUuid" -> msg.partyUuid, "role" -> msg.role))
}
}
case class RelMsg(val partyRelGroupId: String, val partyUuid: String, val role: String)
示例5: OneThousandNodesTest
//设置package包名称以及导入依赖的类
import io.gatling.core.Predef._
import io.gatling.core.scenario.Simulation
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.parsing.json.{JSONObject, JSONArray}
class OneThousandNodesTest extends Simulation {
val httpConf = http
.baseURL("http://localhost:7474")
.acceptHeader("application/json")
.shareConnections
// Uncomment to see the response of each request.
// .extraInfoExtractor(extraInfo => {
// println(extraInfo.response.body.string)
// Nil
// }).disableResponseChunksDiscarding
val random = new util.Random
val cypher = """CREATE ( me { user_id: {user_id} } )"""
val oneThousand = JSONArray.apply(
List.fill(1000)(
JSONObject.apply(
Map("statement" -> cypher,
"parameters" -> JSONObject.apply(
Map("user_id" -> random.nextInt())))
)
)
)
val statements = JSONObject.apply(Map("statements" -> oneThousand))
val scn = scenario("Create 1000 Nodes")
.during(30 seconds) {
exec(
http("create 1000 nodes")
.post("/db/data/transaction/commit")
.basicAuth("neo4j", "swordfish")
.body(StringBody(statements.toString()))
.asJSON
.check(status.is(200))
)
}
setUp(
scn.inject( atOnceUsers(8) ).protocols(httpConf)
)
}
示例6: toJSONObject
//设置package包名称以及导入依赖的类
package pl.edu.agh.sp.tsa.model
import scala.util.parsing.json.JSONObject
def toJSONObject: JSONObject = {
JSONObject.apply(Map(
"statusId" -> statusId,
"userName" -> userName,
"tweetText" -> tweetText,
"fillKey" -> sentiment,
"latitude" -> latitude,
"longitude" -> longitude,
"avatarURL" -> avatarURL,
"creationDate" -> creationDate
))
}
}
示例7: addCustomDictionary
//设置package包名称以及导入依赖的类
package com.ftchinese.jobs.push
import scala.util.parsing.json.JSONFormat._
import scala.util.parsing.json.JSONObject
def addCustomDictionary(key: String, value: Any): Unit ={
value match {
case x: String =>
customs = customs.updated(key, x)
case _ =>
}
}
def getPayload: String = {
var tmp: Map[String, Any] = customs
tmp = tmp + ("aps" -> aps)
mapToJson(tmp)
}
def mapToJson(data: Map[String, Any]): String ={
val ret = data.map( item => {
item._2 match {
case s: String =>
item._1 -> s
case i: Int =>
item._1 -> i
case x: Map[_, _] =>
val tmp = mapToJson(x.asInstanceOf[Map[String, Any]])
item._1 -> tmp.substring(0, tmp.length)
}
})
val formatter: ValueFormatter = {
case s: String =>
if(s.startsWith("{")){
s
} else {
"\"" + s + "\""
}
case x =>
x.toString
}
JSONObject.apply(ret).toString(formatter)
}
}
示例8: Address
//设置package包名称以及导入依赖的类
package models.units.attributes
import io.swagger.annotations.ApiModelProperty
import scala.util.parsing.json.JSONObject
case class Address(
@ApiModelProperty(value = "Street and optional door number", example = "101 Long Street") line1: String,
@ApiModelProperty(value = "Optional field for building or apartment name", example = "Little Winsor") line2: String,
@ApiModelProperty(value = "Town of address", example = "Bury") line3: String,
@ApiModelProperty(value = "City of address", example = "Manchester") line4: String,
@ApiModelProperty(value = "County of address", example = "Gtr Manchester") line5: String
)
object AddressObj {
def toMap(a: Address): Map[String, String] = Map(
"line1" -> a.line1,
"line2" -> a.line2,
"line3" -> a.line3,
"line4" -> a.line4,
"line5" -> a.line5
)
def toJson(a: Address) = JSONObject(toMap(a))
}
示例9: MatchObj
//设置package包名称以及导入依赖的类
package utils
import models.units.{ Enterprise }
import models.units.attributes.{ Address, AddressObj }
import utils.Utilities.{ errAsJson, getElement }
import scala.util.parsing.json.JSONObject
@deprecated("Migrated to Mapping", "alpha/link [Wed 19 July 2017 - 11:15]")
object MatchObj {
private val delim: String = ","
def toMap(m: Enterprise) = Map(
"name" -> m.name,
"enterprise" -> m.id,
"address" -> m.address,
"postcode" -> m.postcode,
"legalStatus" -> m.legalStatus,
"sic" -> m.sic,
"employees" -> m.employees,
"workingGroup" -> m.workingGroup,
"employment" -> m.employment,
"turnover" -> m.turnover,
"source" -> m.source
)
def toString(returned: List[Enterprise]): String = returned.map {
case z => s"""${toMap(z).map(x => s""""${x._1}":${fetch(x._2)}""").mkString(delim)}"""
case _ => errAsJson(404, "missing field", "Cannot find data in field")
}.map(x => s"""{$x}""").mkString("[", delim, "]")
@SuppressWarnings(Array("unused"))
def fromMap(values: Array[String]): Enterprise =
Enterprise(values(0), values(1).toLong, Seq(Option(values(2).toLong), Option(values(3).toLong), Option(values(4).toLong),
Option(values(5).toLong)), Address(values(6), values(7), values(8), values(9), values(10)), values(11),
Option(values(12).toInt), Option(values(13).toInt), Option(values(14).toInt), Option(values(15).toInt),
Option(values(16).toInt), Option(values(17).toLong))
def fetch(elem: Any) = elem match {
case (a: Address) => JSONObject(AddressObj.toMap(a))
case _ => getElement(elem)
}
}