当前位置: 首页>>代码示例>>Scala>>正文


Scala JSONObject类代码示例

本文整理汇总了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)
  )

} 
开发者ID:maxdemarzi,项目名称:cypher_writes_test,代码行数:52,代码来源:OneThousandLabeledNodesTest.scala

示例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 = "") 
开发者ID:zj-lingxin,项目名称:dmp_alipay_loan_balance,代码行数:23,代码来源:Msg.scala

示例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) 
开发者ID:zj-lingxin,项目名称:dmp_relationship_circle,代码行数:19,代码来源:PartyRelWrapper.scala

示例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) 
开发者ID:zj-lingxin,项目名称:dmp_relationship_circle,代码行数:18,代码来源:RelWrapper.scala

示例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)
  )

} 
开发者ID:maxdemarzi,项目名称:cypher_writes_test,代码行数:52,代码来源:OneThousandNodesTest.scala

示例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
    ))
  }

} 
开发者ID:matkluska,项目名称:twitter-stream-analysis-server,代码行数:20,代码来源:TweetWithSentiment.scala

示例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)
    }
} 
开发者ID:FTChinese,项目名称:push,代码行数:54,代码来源:Payload.scala

示例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))

} 
开发者ID:ONSdigital,项目名称:sbr-pipeline-test,代码行数:28,代码来源:Address.scala

示例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)
  }

} 
开发者ID:ONSdigital,项目名称:sbr-pipeline-test,代码行数:47,代码来源:MatchObj.scala


注:本文中的scala.util.parsing.json.JSONObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。