python postman collection_如何解析postmancollection?

我不确定我是否理解您的问题,但如果您尝试迭代json字符串,您可以尝试如下方法:import play.api.libs.json.{JsObject, JsValue, Json}

import scala.util.{Failure, Success, Try}

object JsonParser extends App {

val postman_coolections = "./resources/scala_input.json"

val jsonifiedString = scala.io.Source.fromFile(postman_coolections).mkString

val json: JsValue = Try(Json.parse(jsonifiedString)) match {

case Success(js) => js

case Failure(ex) => throw new Exception("Couldn't parse json", ex)

}

json.asInstanceOf[JsObject].fields.foreach{

case (key: String, value: JsValue)=>

println(s"Key:$key value:${value.toString}")

writeFile(s"$key.json", Json.prettyPrint(value))

}

//writing the whole postman input as a single file

writeFile("postmanInputFormatted.json", Json.prettyPrint(json))

writeFile("postmanInput.json", Json.stringify(json))

// To access individual property one option is to use this approach

val lookedValue = json \ "postData" \ "params" \ 1 \ "hello" \ "test"

lookedValue match {

case JsDefined(value) => println(s"Test value is $value")

case JsUndefined() => println("Didn't find test value")

}

// or

val lookedValueAlt = (json \ "postData" \ "params" \ 1 \ "hello" \ "test").getOrElse(throw SomeException)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值