• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala toJson类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中play.api.libs.json.Json.toJson的典型用法代码示例。如果您正苦于以下问题:Scala toJson类的具体用法?Scala toJson怎么用?Scala toJson使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了toJson类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: RoutesActor

//设置package包名称以及导入依赖的类
package bmpattern


import akka.actor.Actor
import akka.actor.ActorRef
import akka.actor.ActorLogging
import akka.actor.Props

import play.api.libs.json.Json.toJson

import bmmessages._
import akka.actor.Terminated

class RoutesActor extends Actor with ActorLogging {
	var originSender : ActorRef = null
	var next : ActorRef = null
	def receive = {
		case excute(msr)  => {
		    implicit val cm = msr.cm
		    
			originSender = sender
			msr.lst match {
				case Nil => originSender ! toJson("error")
				case head :: tail => {
					head match {
						case p : ParallelMessage => {
							next = context.actorOf(ScatterGatherActor.prop(self, MessageRoutes(tail, msr.rst)), "gate")
							next ! head
						}
						case c : CommonMessage => {
							next = context.actorOf(PipeFilterActor.prop(self, MessageRoutes(tail, msr.rst)), "gate")
							next ! head
						}
					}
					
					context.watch(next)
				}
			}
		}
		case result(rst) => {
			originSender ! rst
			cancelActor
		}
		case error(err) => {
			originSender ! err
			cancelActor
		}
		case bmmessages.timeout() => {
			originSender ! toJson("timeout")
			cancelActor
		}
		case Terminated(actorRef) => println("Actor {} terminated", actorRef)
		case _ => Unit
 	}
	
	def cancelActor = {
		context.stop(self)
	}
} 
开发者ID:AlfredYang1986,项目名称:arch-started,代码行数:60,代码来源:RoutesActor.scala


示例2: msg_LogCommand

//设置package包名称以及导入依赖的类
package bmpattern

import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson
import bmmessages.CommonMessage
import bmutil.errorcode.ErrorCode

import org.apache.log4j.Logger

abstract class msg_LogCommand extends CommonMessage

object LogMessage {
    implicit val common_log : (JsValue, JsValue) => (Option[Map[String, JsValue]], Option[JsValue]) = (ls, data) => {
        try {
            val logger = Logger.getRootLogger

            val user_id = (data \ "user_id").asOpt[String].map (x => x).getOrElse("unknown user")
            val method = (ls \ "method").asOpt[String].map (x => x).getOrElse(throw new Exception("log struct error"))

            logger.info(s"$user_id call $method with args ${data.toString}")
            (Some(Map("status" -> toJson("ok"))), None)

        } catch {
            case ex : Exception => (None, Some(ErrorCode.errorToJson(ex.getMessage)))
        }
    }

    case class msg_log(ls : JsValue, data : JsValue)(implicit val l : (JsValue, JsValue) => (Option[Map[String, JsValue]], Option[JsValue])) extends msg_LogCommand
} 
开发者ID:AlfredYang1986,项目名称:arch-started,代码行数:30,代码来源:LogMessage.scala


示例3: PhoneSMSController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import akka.actor.ActorSystem
import bminjection.db.DBTrait
import bmlogic.auth.AuthMessage.msg_AuthQuery
import play.api.mvc._
import bmlogic.common.requestArgsQuery
import bmlogic.phonecode.PhoneCodeMessages.{msg_CheckSMSCode, msg_SendSMSCode}
import bmmessages.{CommonModules, MessageRoutes}
import bmpattern.LogMessage.msg_log
import bmpattern.ResultMessage.msg_CommonResultMessage
import play.api.libs.json.Json.toJson

class PhoneSMSController @Inject () (as_inject : ActorSystem, dbt : DBTrait) extends Controller {
    implicit val as = as_inject

    def sendSMSCode = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.ResultMessage.common_result
        import bmpattern.LogMessage.common_log
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("send sms code"))), jv) :: msg_AuthQuery(jv)
            :: msg_SendSMSCode(jv) :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt))))
    })
    def checkSMSCode = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.ResultMessage.common_result
        import bmpattern.LogMessage.common_log
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("check sms code"))), jv)
            :: msg_CheckSMSCode(jv) :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt))))
    })
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:32,代码来源:PhoneSMSController.scala


示例4: ProfileController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import akka.actor.ActorSystem
import bminjection.db.DBTrait
import bminjection.token.AuthTokenTrait
import bmlogic.auth.AuthMessage.{msg_AuthTokenParser, msg_CheckTokenExpire}
import bmlogic.common.requestArgsQuery
import bmlogic.profile.ProfileMessage._
import bmmessages.{CommonModules, MessageRoutes}
import bmpattern.LogMessage.msg_log
import bmpattern.ResultMessage.msg_CommonResultMessage
import play.api.libs.json.Json.toJson
import play.api.mvc._

class ProfileController @Inject () (as_inject : ActorSystem, dbt : DBTrait, att : AuthTokenTrait) extends Controller {
    implicit val as = as_inject

    def queryProfile = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("query profile"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_ProfileQuery(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })

    def searchProfile = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("search profile"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_ProfileSearch(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })

    def queryMultiProfile = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("multi profile"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_ProfileMultiQuery(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })

    def updateProfile = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("update profile"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_ProfileCanUpdate(jv)
            :: msg_ProfileUpdate(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:57,代码来源:ProfileController.scala


示例5: SelectedController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import akka.actor.ActorSystem
import bminjection.db.DBTrait
import bminjection.token.AuthTokenTrait
import bmlogic.auth.AuthMessage.{msg_AuthTokenParser, msg_CheckTokenExpire}
import bmlogic.collections.CollectionsMessage.msg_QueryUserCollections
import bmlogic.common.requestArgsQuery
import bmlogic.dongdaselectedservice.SelectedServiceMessages.{msg_LstServiceSelected, msg_PopSelectedService, msg_PushSelectedService, msg_QuerySelectedService}
import bmlogic.kidnap.KidnapMessage.{msg_KidnapDetail, msg_KidnapMultiQuery}
import bmlogic.profile.ProfileMessage.msg_ProfileMultiQuery
import bmmessages.{CommonModules, MessageRoutes}
import bmpattern.LogMessage.msg_log
import bmpattern.ParallelMessage
import bmpattern.ResultMessage.msg_CommonResultMessage
import play.api.libs.json.Json.toJson
import play.api.mvc.{Action, Controller}

class SelectedController @Inject () (as_inject : ActorSystem, dbt : DBTrait, att : AuthTokenTrait) extends Controller {
    implicit val as = as_inject

    def pushSelectedService = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("push selected service"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_KidnapDetail(jv)
            :: msg_PushSelectedService(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })

    def popSelectedService = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("pop selected service"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_PopSelectedService(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })

    def searchSelectedService = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        import bmlogic.kidnap.KidnapModule.serviceResultMerge
        implicit val cm = (CommonModules(Some(Map("db" -> dbt, "att" -> att))))
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("search selected service"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_QuerySelectedService(jv)
            :: msg_KidnapMultiQuery(jv)
            ::
            ParallelMessage(
                MessageRoutes(msg_LstServiceSelected(jv) :: Nil, None) ::
                MessageRoutes(msg_QueryUserCollections(jv) :: Nil, None) ::
                MessageRoutes(msg_ProfileMultiQuery(jv) :: Nil, None) :: Nil, serviceResultMerge)
            :: msg_CommonResultMessage() :: Nil, None)
    })
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:60,代码来源:SelectedController.scala


示例6: AuthController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject._

import akka.actor.ActorSystem
import bminjection.db.DBTrait
import bminjection.notification.DDNTrait
import bminjection.token.AuthTokenTrait
import bmlogic.auth.AuthMessage._
import bmlogic.common.requestArgsQuery
import bmlogic.phonecode.PhoneCodeMessages.msg_CheckSMSCode
import bmlogic.emxmpp.EMMessages.msg_RegisterEMUser
import bmmessages._
import bmpattern.LogMessage.msg_log
import bmpattern.ResultMessage.msg_CommonResultMessage
import play.api.libs.json.Json.toJson
import play.api.mvc._

class AuthController @Inject () (as_inject : ActorSystem, dbt : DBTrait, att : AuthTokenTrait, ddn : DDNTrait) extends Controller {
    implicit val as = as_inject

    def authLogin = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
            import bmpattern.LogMessage.common_log
            import bmpattern.ResultMessage.common_result
            MessageRoutes(msg_log(toJson(Map("method" -> toJson("dongda login"))), jv)
                :: msg_AuthLogin(jv) :: msg_RegisterEMUser(jv) :: msg_GenerateToken()
                :: msg_CommonResultMessage() :: Nil, None)(
                CommonModules(Some(Map(
                    "db" -> dbt, "att" -> att,
                    "ddn" -> ddn, "as" -> as))))
        })

    def authWithPhoneCode = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
            import bmpattern.LogMessage.common_log
            import bmpattern.ResultMessage.common_result
            MessageRoutes(msg_log(toJson(Map("method" -> toJson("dongda login phone code"))), jv)
                :: msg_CheckSMSCode(jv)
                :: msg_AuthLogin(jv) :: msg_RegisterEMUser(jv) :: msg_GenerateToken()
                :: msg_CommonResultMessage() :: Nil, None)(
                CommonModules(Some(Map(
                    "db" -> dbt, "att" -> att,
                    "ddn" -> ddn, "as" -> as))))
        })

    def authWithSNS = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
            import bmpattern.LogMessage.common_log
            import bmpattern.ResultMessage.common_result
            MessageRoutes(msg_log(toJson(Map("method" -> toJson("dongda login phone code"))), jv)
                :: msg_AuthLogin(jv) :: msg_RegisterEMUser(jv) :: msg_GenerateToken()
                :: msg_CommonResultMessage() :: Nil, None)(
                CommonModules(Some(Map(
                    "db" -> dbt, "att" -> att,
                    "ddn" -> ddn, "as" -> as))))
        })
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:56,代码来源:AuthController.scala


示例7: CollectionsController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject.Inject

import akka.actor.ActorSystem
import bminjection.db.DBTrait
import bminjection.token.AuthTokenTrait
import bmlogic.auth.AuthMessage.{msg_AuthTokenParser, msg_CheckTokenExpire}
import bmlogic.collections.CollectionsMessage._
import bmlogic.common.requestArgsQuery
import bmmessages.{CommonModules, MessageRoutes}
import bmpattern.LogMessage.msg_log
import bmpattern.ResultMessage.msg_CommonResultMessage
import play.api.libs.json.Json.toJson
import play.api.mvc.Action

class CollectionsController @Inject () (as_inject : ActorSystem, dbt : DBTrait, att : AuthTokenTrait) {
    implicit val as = as_inject

    def pushCollection = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("push collection"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_CollectionPush(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })

    def popCollection = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("pop collection"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_CollectionPop(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })

    def queryUserCollections = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("user collections"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_QueryUserCollections(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })

    def queryCollectedUser = Action (request => requestArgsQuery().requestArgsV2(request) { jv =>
        import bmpattern.LogMessage.common_log
        import bmpattern.ResultMessage.common_result
        MessageRoutes(msg_log(toJson(Map("method" -> toJson("collected users"))), jv)
            :: msg_AuthTokenParser(jv) :: msg_CheckTokenExpire(jv)
            :: msg_QueryCollectedUsers(jv)
            :: msg_CommonResultMessage() :: Nil, None)(CommonModules(Some(Map("db" -> dbt, "att" -> att))))
    })
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:56,代码来源:CollectionsController.scala


示例8: conditions

//设置package包名称以及导入依赖的类
package bmlogic.auth.AuthData

import com.mongodb.casbah.Imports._
import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson


trait AuthData {

    def conditions(data : JsValue) : DBObject = {
        val builder = MongoDBObject.newBuilder

        (data \ "phone").asOpt[String].map (x => builder += "auth_phone" -> x).getOrElse(Unit)
        (data \ "user_id").asOpt[String].map (x => builder += "user_id" -> x).getOrElse(Unit)
        (data \ "screen_name").asOpt[String].map (x => builder += "screen_name" -> x).getOrElse(Unit)

        builder.result
    }

    implicit val m2d : JsValue => DBObject = { js =>
        val builder = MongoDBObject.newBuilder

        builder += "screen_name" -> (js \ "screen_name").asOpt[String].map (x => x).getOrElse("")
        builder += "screen_photo" -> (js \ "screen_photo").asOpt[String].map (x => x).getOrElse("")

        (js \ "phone").asOpt[String].map { x =>
            builder += "auth_phone" -> x
        }.getOrElse(Unit)

        (js \ "third").asOpt[JsValue].map { x =>
            val name = (x \ "provide_name").asOpt[String].map (x => x).getOrElse(throw new Exception("user push error"))

            val third_builder = MongoDBObject.newBuilder
            third_builder += "uid" -> (x \ "provide_uid").asOpt[String].map (x => x).getOrElse(throw new Exception("user push error"))
            third_builder += "token" -> (x \ "provide_token").asOpt[String].map (x => x).getOrElse(throw new Exception("user push error"))

            builder += "screen_name" -> (x \ "provide_screen_name").asOpt[String].map (x => x).getOrElse(throw new Exception("user push error"))
            builder += "screen_photo" -> (x \ "provide_screen_photo").asOpt[String].map (x => x).getOrElse(throw new Exception("user push error"))
            builder += name -> third_builder.result
        }

        builder.result
    }

    implicit val d2m : DBObject => Map[String, JsValue] = { obj =>
        Map(
            "user_id" -> toJson(obj.getAs[String]("user_id").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "screen_name" -> toJson(obj.getAs[String]("screen_name").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "screen_photo" -> toJson(obj.getAs[String]("screen_photo").map (x => x).getOrElse(throw new Exception("db prase error")))
        )
    }
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:53,代码来源:AuthData.scala


示例9:

//设置package包名称以及导入依赖的类
package bmlogic.dongdaselectedservice.SelectedServiceData

import com.mongodb.casbah.Imports._
import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson

trait SelectedServiceResult {
    implicit val sr : DBObject => Map[String, JsValue] = { obj =>
        Map(
            "selected_id" -> toJson(obj.getAs[String]("selected_id").map (x => x).getOrElse(throw new Exception("dongda selected output"))),
            "category" -> toJson(obj.getAs[String]("category").map (x => x).getOrElse(throw new Exception("dongda selected output"))),
            "group" -> toJson(obj.getAs[String]("group").map (x => x).getOrElse(throw new Exception("dongda selected output"))),
            "service_id" -> toJson(obj.getAs[String]("service_id").map (x => x).getOrElse(throw new Exception("dongda selected output error")))
        )
    }
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:17,代码来源:SelectedServiceResult.scala


示例10:

//设置package包名称以及导入依赖的类
package bmlogic.phonecode.PhoneCodeData

import bmlogic.common.sercurity.Sercurity
import com.mongodb.casbah.Imports._
import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson

trait PhoneCodeData {
    implicit val m2d : JsValue => DBObject = { js =>
        val builder = MongoDBObject.newBuilder

        val phoneNo = (js \ "phone").asOpt[String].map (x => x).getOrElse(throw new Exception("reg push error"))
        val reg_token = Sercurity.md5Hash(phoneNo + Sercurity.getTimeSpanWithMinutes)
        val code = 1111.toString // fake one
//		val code = (scala.util.Random.nextInt(9000) + 1000).toString

        builder += "phone" -> phoneNo
        builder += "code" -> code
        builder += "reg_token" -> reg_token

        builder.result
    }

    implicit val d2m : DBObject => Map[String, JsValue] = { obj =>
        Map(
            "phone" -> toJson(obj.getAs[String]("phone").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "code" -> toJson(obj.getAs[String]("code").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "reg_token" -> toJson(obj.getAs[String]("reg_token").map (x => x).getOrElse(throw new Exception("db prase error")))
        )
    }
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:32,代码来源:PhoneCodeData.scala


示例11:

//设置package包名称以及导入依赖的类
package bmlogic.collections.CollectionData

import com.mongodb.casbah.Imports._
import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson

trait CollectionResult {
    implicit val drbu : DBObject => Map[String, JsValue] = { obj =>
        val service_lst = obj.getAs[MongoDBList]("services").get.toList.asInstanceOf[List[String]]
        Map(
            "user_id" -> toJson(obj.getAs[String]("user_id").map (x => x).getOrElse(throw new Exception("collection output error"))),
            "services" -> toJson(service_lst)
        )
    }

    implicit val drbk : DBObject => Map[String, JsValue] = { obj =>
        val user_lst = obj.getAs[MongoDBList]("users").get.toList.asInstanceOf[List[String]]
        Map(
            "service_id" -> toJson(obj.getAs[String]("service_id").map (x => x).getOrElse(throw new Exception("collection output error"))),
            "users" -> toJson(user_lst)
        )
    }
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:24,代码来源:CollectionResult.scala


示例12:

//设置package包名称以及导入依赖的类
package bmlogic.timemanager.TimemanagerData

import com.mongodb.casbah.Imports._
import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson

trait TimemanagerResult {
    implicit val dr : DBObject => Map[String, JsValue] = { obj =>
        val tms = obj.getAs[MongoDBList]("tms").get.toList.asInstanceOf[List[BasicDBObject]]

        Map(
            "service_id" -> toJson(obj.getAs[String]("service_id").map (x => x).getOrElse(throw new Exception("tm output error"))),
            "tms" ->
                toJson(tms.map { one =>
                    toJson(Map("pattern" -> toJson(one.get("pattern").asInstanceOf[Number].intValue),
                                "startdate" -> toJson(one.get("startdate").asInstanceOf[Number].longValue),
                                "enddate" -> toJson(one.get("enddate").asInstanceOf[Number].longValue),
                                "starthours" -> toJson(one.get("starthours").asInstanceOf[Number].longValue),
                                "endhours" -> toJson(one.get("endhours").asInstanceOf[Number].longValue())))
            })
        )
    }
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:24,代码来源:TimemanagerResult.scala


示例13: ault

//设置package包名称以及导入依赖的类
package bmlogic.timemanager.TimemanagerData

import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson

trait TimemanagerDefaultResult {
    implicit val default : JsValue => Map[String, JsValue] = { obj =>
        val sid = (obj \ "condition" \ "service_id").asOpt[String].map (x => x).getOrElse(throw new Exception("service not exist"))

        Map(
            "service_id" -> toJson(sid),
            "tms" ->
                toJson(
                    toJson(Map("pattern" -> toJson(0), // daily
                               "startdate" -> toJson(0), // 1970-01-01
                               "enddate" -> toJson(-1), // to forever
                               "starthours" -> toJson(800), // 8:00 am
                               "endhours" -> toJson(2000)) :: Nil
                )
            )
        )
    }
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:24,代码来源:TimemanagerDefaultResult.scala


示例14:

//设置package包名称以及导入依赖的类
package bmlogic.profile.ProfileConditions

import com.mongodb.casbah.Imports._
import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson

trait profileResults {
    implicit val sr : DBObject => Map[String, JsValue] = { obj =>
        Map(
            "user_id" -> toJson(obj.getAs[String]("user_id").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "screen_name" -> toJson(obj.getAs[String]("screen_name").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "screen_photo" -> toJson(obj.getAs[String]("screen_photo").map (x => x).getOrElse(throw new Exception("db prase error")))
        )
    }

    implicit val dr : DBObject => Map[String, JsValue] = { obj =>
        val spm = obj.getAs[MongoDBObject]("service_provider").map { x =>
            Map(
                "owner_name" -> toJson(x.getAs[String]("owner_name").map (x => x).getOrElse(throw new Exception("db prase error"))),
                "social_id" -> toJson(x.getAs[String]("social_id").map (x => x).getOrElse(throw new Exception("db prase error"))),
                "company" -> toJson(x.getAs[String]("company").map (x => x).getOrElse("")),
                "description" -> toJson(x.getAs[String]("description").map (x => x).getOrElse("")),
                "address" -> toJson(x.getAs[String]("address").map (x => x).getOrElse("")),
                "contact_no" -> toJson(x.getAs[String]("contact_no").map (x => x).getOrElse(""))
            )
        }.getOrElse(Map.empty[String, JsValue])

        Map(
            "user_id" -> toJson(obj.getAs[String]("user_id").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "screen_name" -> toJson(obj.getAs[String]("screen_name").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "screen_photo" -> toJson(obj.getAs[String]("screen_photo").map (x => x).getOrElse(throw new Exception("db prase error"))),
            "is_service_provider" -> toJson(if (spm.isEmpty) 0
                                            else 1)
        ) ++ spm
    }
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:37,代码来源:profileResults.scala


示例15:

//设置package包名称以及导入依赖的类
package bmlogic.order.OrderData

import com.mongodb.casbah.Imports._
import play.api.libs.json.JsValue
import play.api.libs.json.Json.toJson

trait OrderResult {
    implicit val dr : DBObject => Map[String, JsValue] = { obj =>
        Map(
            "order_id" -> toJson(obj.getAs[String]("order_id").map (x => x).getOrElse(throw new Exception("order output error"))),
            "service_id" -> toJson(obj.getAs[String]("service_id").map (x => x).getOrElse(throw new Exception("order output error"))),
            "owner_id" -> toJson(obj.getAs[String]("owner_id").map (x => x).getOrElse(throw new Exception("order output error"))),
            "order_title" -> toJson(obj.getAs[String]("order_title").map (x => x).getOrElse(throw new Exception("order output error"))),
            "order_thumbs" -> toJson(obj.getAs[String]("order_thumbs").map (x => x).getOrElse(throw new Exception("order output error"))),
            "total_fee" -> toJson(obj.getAs[Number]("total_fee").map (x => x.intValue).getOrElse(throw new Exception("order output error"))),
            "further_message" -> toJson(obj.getAs[String]("further_message").map (x => x).getOrElse(throw new Exception("order output error"))),
            "prepay_id" -> toJson(obj.getAs[String]("further_message").map (x => x).getOrElse(throw new Exception("order output error")))
        )
    }
} 
开发者ID:AlfredYang1986,项目名称:Dongda-Service,代码行数:21,代码来源:OrderResult.scala


示例16: ApplicationController

//设置package包名称以及导入依赖的类
package controllers

import javax.inject._
import play.api._
import models.UserLoginForm
import play.api.libs.json.Json.toJson
import play.api.libs.json.{JsSuccess, Json, Reads}
import play.api.mvc._

@Singleton
class ApplicationController @Inject()(cc: ControllerComponents) extends AbstractController(cc){

  def index() =  Action{
    Ok(views.html.login()).withNewSession
  }

  def login() = Action(parse.json){request =>

    implicit  val loginRequest: Reads[UserLoginForm] = Json.reads[UserLoginForm]

    request.body.validate[UserLoginForm] match {
      case s: JsSuccess[UserLoginForm] if true => {
        Ok(toJson(Map("valid" -> true))).withSession("user" -> s.get.username)
      }
      case _ => Forbidden(toJson(Map("valid" -> false)))
    }
  }

} 
开发者ID:lincex7845,项目名称:owasp,代码行数:30,代码来源:ApplicationController.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala Broadcast类代码示例发布时间:2022-05-23
下一篇:
Scala TemporaryFile类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap