- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有 Json
字符串:
[{"cid":"1039420885783365","name":"","s":"TSLA160916C00005000","e":"OPRA","p":"219.64","cs":"chb","c":"0.00","cp":"0.00","b":"190.30","a":"194.85","oi":"2","vol":"-","strike":"5.00","expiry":"Sep 16, 2016"}, ... ]
我的代码:
case class OptionEntry(cid: String,
name: String,
s: String,
e: String,
p: String,
cs: String,
c: String,
cp: String,
b: String,
a: String,
oi: String,
vol: String,
strike: String,
expiry: String)
val optionEntries = Json.parse(jsonString)
implicit val optionEntryReads: Reads[OptionEntry] = (
(JsPath \ "cid").read[String] and
(JsPath \ "name").read[String] and
(JsPath \ "s").read[String] and
(JsPath \ "e").read[String] and
(JsPath \ "p").read[String] and
(JsPath \ "cs").read[String] and
(JsPath \ "c").read[String] and
(JsPath \ "cp").read[String] and
(JsPath \ "b").read[String] and
(JsPath \ "a").read[String] and
(JsPath \ "oi").read[String] and
(JsPath \ "vol").read[String] and
(JsPath \ "strike").read[String] and
(JsPath \ "expiry").read[String]
)(OptionEntry.apply _)
println(optionEntries.validate[List[OptionEntry]])
Json 字符串:
[{"cid":"1039420885783365","name":"","s":"TSLA160916C00005000","e":"OPRA","p":"219.64","cs":"chb","c":"0.00","cp":"0.00","b":"194.70","a":"197.90","oi":"2","vol":"-","strike":"5.00","expiry":"Sep 16, 2016"},{"cid":"259816193292639","name":"","s":"TSLA160916C00010000","e":"OPRA","p":"182.50","cs":"chb","c":"0.00","cp":"0.00","b":"189.85","a":"192.75","oi":"0","vol":"-","strike":"10.00","expiry":"Sep 16, 2016"},{"cid":"834521657091252","name":"","s":"TSLA160916C00015000","e":"OPRA","p":"211.09","cs":"chb","c":"0.00","cp":"0.00","b":"184.80","a":"187.20","oi":"1","vol":"-","strike":"15.00","expiry":"Sep 16, 2016"},{"cid":"58038573817889","name":"","s":"TSLA160916C00020000","e":"OPRA","p":"206.06","cs":"chb","c":"0.00","cp":"0.00","b":"179.70","a":"182.20","oi":"1","vol":"-","strike":"20.00","expiry":"Sep 16, 2016"},{"cid":"400783271986149","name":"","s":"TSLA160916C00025000","e":"OPRA","p":"151.58","cs":"chb","c":"0.00","cp":"0.00","b":"174.85","a":"177.70","oi":"0","vol":"-","strike":"25.00","expiry":"Sep 16, 2016"},{"cid":"397108163551042","name":"","s":"TSLA160916C00030000","e":"OPRA","p":"-","c":"-","b":"169.85","a":"172.70","oi":"0","vol":"-","strike":"30.00","expiry":"Sep 16, 2016"},{"cid":"39807976369121","name":"","s":"TSLA160916C00035000","e":"OPRA","p":"-","c":"-","b":"164.70","a":"167.70","oi":"0","vol":"-","strike":"35.00","expiry":"Sep 16, 2016"},{"cid":"162843593973912","name":"","s":"TSLA160916C00040000","e":"OPRA","p":"186.17","cs":"chb","c":"0.00","cp":"0.00","b":"159.85","a":"162.25","oi":"1","vol":"-","strike":"40.00","expiry":"Sep 16, 2016"},{"cid":"105072414761672","name":"","s":"TSLA160916C00045000","e":"OPRA","p":"208.10","cs":"chb","c":"0.00","cp":"0.00","b":"154.85","a":"157.75","oi":"1","vol":"-","strike":"45.00","expiry":"Sep 16, 2016"},{"cid":"839642082077864","name":"","s":"TSLA160916C00050000","e":"OPRA","p":"158.00","cs":"chb","c":"0.00","cp":"0.00","b":"149.85","a":"152.90","oi":"0","vol":"-","strike":"50.00","expiry":"Sep 16, 2016"},{"cid":"738268109616581","name":"","s":"TSLA160916C00055000","e":"OPRA","p":"171.43","cs":"chb","c":"0.00","cp":"0.00","b":"144.50","a":"147.40","oi":"1","vol":"-","strike":"55.00","expiry":"Sep 16, 2016"},{"cid":"1110347752052358","name":"","s":"TSLA160916C00060000","e":"OPRA","p":"-","c":"-","b":"139.50","a":"142.75","oi":"0","vol":"-","strike":"60.00","expiry":"Sep 16, 2016"},{"cid":"701783145177326","name":"","s":"TSLA160916C00065000","e":"OPRA","p":"-","c":"-","b":"134.50","a":"137.75","oi":"0","vol":"-","strike":"65.00","expiry":"Sep 16, 2016"},{"cid":"654322547204560","name":"","s":"TSLA160916C00070000","e":"OPRA","p":"149.88","cs":"chb","c":"0.00","cp":"0.00","b":"129.70","a":"132.75","oi":"0","vol":"-","strike":"70.00","expiry":"Sep 16, 2016"},{"cid":"741226138508078","name":"","s":"TSLA160916C00075000","e":"OPRA","p":"-","c":"-","b":"124.50","a":"127.75","oi":"0","vol":"-","strike":"75.00","expiry":"Sep 16, 2016"},{"cid":"972168634803798","name":"","s":"TSLA160916C00080000","e":"OPRA","p":"-","c":"-","b":"119.50","a":"122.75","oi":"0","vol":"-","strike":"80.00","expiry":"Sep 16, 2016"},{"cid":"986485863274043","name":"","s":"TSLA160916C00085000","e":"OPRA","p":"-","c":"-","b":"114.50","a":"117.85","oi":"0","vol":"-","strike":"85.00","expiry":"Sep 16, 2016"},{"cid":"1095545768550226","name":"","s":"TSLA160916C00090000","e":"OPRA","p":"138.52","cs":"chb","c":"0.00","cp":"0.00","b":"109.85","a":"112.20","oi":"0","vol":"-","strike":"90.00","expiry":"Sep 16, 2016"},{"cid":"26254300000394","name":"","s":"TSLA160916C00095000","e":"OPRA","p":"127.10","cs":"chb","c":"0.00","cp":"0.00","b":"104.70","a":"107.90","oi":"0","vol":"-","strike":"95.00","expiry":"Sep 16, 2016"},{"cid":"1118117726847457","name":"","s":"TSLA160916C00100000","e":"OPRA","p":"123.27","cs":"chb","c":"0.00","cp":"0.00","b":"99.50","a":"102.15","oi":"13","vol":"-","strike":"100.00","expiry":"Sep 16, 2016"},{"cid":"245141050010264","name":"","s":"TSLA160916C00105000","e":"OPRA","p":"95.29","cs":"chb","c":"0.00","cp":"0.00","b":"94.70","a":"97.90","oi":"0","vol":"-","strike":"105.00","expiry":"Sep 16, 2016"},{"cid":"439847478157007","name":"","s":"TSLA160916C00110000","e":"OPRA","p":"100.90","cs":"chb","c":"0.00","cp":"0.00","b":"89.50","a":"92.20","oi":"0","vol":"-","strike":"110.00","expiry":"Sep 16, 2016"},{"cid":"41101379521672","name":"","s":"TSLA160916C00115000","e":"OPRA","p":"114.53","cs":"chb","c":"0.00","cp":"0.00","b":"84.70","a":"87.20","oi":"0","vol":"-","strike":"115.00","expiry":"Sep 16, 2016"},{"cid":"140943872831911","name":"","s":"TSLA160916C00120000","e":"OPRA","p":"105.36","cs":"chb","c":"0.00","cp":"0.00","b":"79.70","a":"82.90","oi":"0","vol":"-","strike":"120.00","expiry":"Sep 16, 2016"},{"cid":"966450180416270","name":"","s":"TSLA160916C00125000","e":"OPRA","p":"108.00","cs":"chb","c":"0.00","cp":"0.00","b":"74.85","a":"77.20","oi":"0","vol":"-","strike":"125.00","expiry":"Sep 16, 2016"},{"cid":"244268213784819","name":"","s":"TSLA160916C00130000","e":"OPRA","p":"93.40","cs":"chb","c":"0.00","cp":"0.00","b":"69.85","a":"72.30","oi":"11","vol":"-","strike":"130.00","expiry":"Sep 16, 2016"},{"cid":"439803738360712","name":"","s":"TSLA160916C00135000","e":"OPRA","p":"82.23","cs":"chb","c":"0.00","cp":"0.00","b":"64.70","a":"67.80","oi":"1","vol":"-","strike":"135.00","expiry":"Sep 16, 2016"},{"cid":"338143164805850","name":"","s":"TSLA160916C00140000","e":"OPRA","p":"88.79","cs":"chb","c":"0.00","cp":"0.00","b":"59.85","a":"62.85","oi":"1","vol":"-","strike":"140.00","expiry":"Sep 16, 2016"},{"cid":"384979845128979","name":"","s":"TSLA160916C00145000","e":"OPRA","p":"66.55","cs":"chb","c":"0.00","cp":"0.00","b":"54.85","a":"57.20","oi":"4","vol":"-","strike":"145.00","expiry":"Sep 16, 2016"},{"cid":"704065395489746","name":"","s":"TSLA160916C00150000","e":"OPRA","p":"60.00","cs":"chb","c":"0.00","cp":"0.00","b":"49.45","a":"52.20","oi":"21","vol":"-","strike":"150.00","expiry":"Sep 16, 2016"},{"cid":"942910344574849","name":"","s":"TSLA160916C00155000","e":"OPRA","p":"56.00","cs":"chb","c":"0.00","cp":"0.00","b":"44.50","a":"47.20","oi":"28","vol":"-","strike":"155.00","expiry":"Sep 16, 2016"},{"cid":"751610325900763","name":"","s":"TSLA160916C00160000","e":"OPRA","p":"42.00","cs":"chr","c":"-8.50","cp":"-16.83","b":"40.75","a":"41.30","oi":"8","vol":"10","strike":"160.00","expiry":"Sep 16, 2016"},{"cid":"580000290226652","name":"","s":"TSLA160916C00165000","e":"OPRA","p":"45.85","cs":"chb","c":"0.00","cp":"0.00","b":"34.80","a":"38.10","oi":"9","vol":"-","strike":"165.00","expiry":"Sep 16, 2016"},{"cid":"446084522487295","name":"","s":"TSLA160916C00170000","e":"OPRA","p":"27.00","cs":"chb","c":"0.00","cp":"0.00","b":"30.05","a":"32.10","oi":"12","vol":"-","strike":"170.00","expiry":"Sep 16, 2016"},{"cid":"367689129200491","name":"","s":"TSLA160916C00175000","e":"OPRA","p":"36.20","cs":"chb","c":"0.00","cp":"0.00","b":"25.15","a":"27.25","oi":"52","vol":"-","strike":"175.00","expiry":"Sep 16, 2016"},{"cid":"129646035642327","name":"","s":"TSLA160916C00180000","e":"OPRA","p":"17.20","cs":"chb","c":"0.00","cp":"0.00","b":"20.85","a":"22.05","oi":"91","vol":"-","strike":"180.00","expiry":"Sep 16, 2016"},{"cid":"733865215077307","name":"","s":"TSLA160916C00185000","e":"OPRA","p":"16.00","cs":"chg","c":"+2.50","cp":"18.52","b":"16.45","a":"17.40","oi":"34","vol":"33","strike":"185.00","expiry":"Sep 16, 2016"},{"cid":"568231138866100","name":"","s":"TSLA160916C00190000","e":"OPRA","p":"13.50","cs":"chg","c":"+3.45","cp":"34.33","b":"12.20","a":"12.65","oi":"855","vol":"8","strike":"190.00","expiry":"Sep 16, 2016"},{"cid":"427189940524630","name":"","s":"TSLA160916C00195000","e":"OPRA","p":"8.40","cs":"chg","c":"+1.75","cp":"26.32","b":"8.50","a":"8.85","oi":"1102","vol":"21","strike":"195.00","expiry":"Sep 16, 2016"},{"cid":"1082141592051119","name":"","s":"TSLA160916C00200000","e":"OPRA","p":"5.55","cs":"chg","c":"+1.40","cp":"33.73","b":"5.40","a":"5.65","oi":"1990","vol":"364","strike":"200.00","expiry":"Sep 16, 2016"},{"cid":"230121558689237","name":"","s":"TSLA160916C00205000","e":"OPRA","p":"3.47","cs":"chg","c":"+1.12","cp":"47.66","b":"3.15","a":"3.35","oi":"1324","vol":"455","strike":"205.00","expiry":"Sep 16, 2016"},{"cid":"894705236612609","name":"","s":"TSLA160916C00210000","e":"OPRA","p":"1.94","cs":"chg","c":"+0.65","cp":"50.39","b":"1.72","a":"1.80","oi":"3867","vol":"681","strike":"210.00","expiry":"Sep 16, 2016"},{"cid":"40801284708400","name":"","s":"TSLA160916C00215000","e":"OPRA","p":"0.94","cs":"chg","c":"+0.23","cp":"32.39","b":"0.90","a":"0.96","oi":"2711","vol":"375","strike":"215.00","expiry":"Sep 16, 2016"},{"cid":"529249705826744","name":"","s":"TSLA160916C00220000","e":"OPRA","p":"0.49","cs":"chg","c":"+0.10","cp":"25.64","b":"0.47","a":"0.52","oi":"4705","vol":"173","strike":"220.00","expiry":"Sep 16, 2016"},{"cid":"579788906485048","name":"","s":"TSLA160916C00225000","e":"OPRA","p":"0.31","cs":"chg","c":"+0.06","cp":"24.00","b":"0.26","a":"0.31","oi":"3102","vol":"105","strike":"225.00","expiry":"Sep 16, 2016"},{"cid":"695785114703989","name":"","s":"TSLA160916C00230000","e":"OPRA","p":"0.18","cs":"chg","c":"+0.02","cp":"12.50","b":"0.15","a":"0.21","oi":"4291","vol":"142","strike":"230.00","expiry":"Sep 16, 2016"},{"cid":"294592085765220","name":"","s":"TSLA160916C00235000","e":"OPRA","p":"0.13","cs":"chg","c":"+0.04","cp":"44.44","b":"0.09","a":"0.15","oi":"2715","vol":"40","strike":"235.00","expiry":"Sep 16, 2016"},{"cid":"614241625252","name":"","s":"TSLA160916C00240000","e":"OPRA","p":"0.05","cs":"chr","c":"-0.06","cp":"-54.55","b":"0.05","a":"0.12","oi":"4062","vol":"11","strike":"240.00","expiry":"Sep 16, 2016"},{"cid":"35412973124711","name":"","s":"TSLA160916C00245000","e":"OPRA","p":"0.15","cs":"chg","c":"+0.09","cp":"150.00","b":"0.05","a":"0.15","oi":"1359","vol":"8","strike":"245.00","expiry":"Sep 16, 2016"},{"cid":"523084247103734","name":"","s":"TSLA160916C00250000","e":"OPRA","p":"0.05","cs":"chg","c":"+0.02","cp":"66.67","b":"0.05","a":"0.10","oi":"12156","vol":"6","strike":"250.00","expiry":"Sep 16, 2016"},{"cid":"386089758942689","name":"","s":"TSLA160916C00255000","e":"OPRA","p":"0.14","cs":"chg","c":"+0.10","cp":"250.00","b":"0.01","a":"0.14","oi":"4097","vol":"1","strike":"255.00","expiry":"Sep 16, 2016"},{"cid":"342874639110958","name":"","s":"TSLA160916C00260000","e":"OPRA","p":"0.05","cs":"chg","c":"+0.02","cp":"66.67","b":"0.01","a":"0.06","oi":"5511","vol":"13","strike":"260.00","expiry":"Sep 16, 2016"},{"cid":"951449640597665","name":"","s":"TSLA160916C00265000","e":"OPRA","p":"0.03","cs":"chr","c":"-0.06","cp":"-66.67","b":"0.01","a":"0.04","oi":"693","vol":"4","strike":"265.00","expiry":"Sep 16, 2016"},{"cid":"109380551285141","name":"","s":"TSLA160916C00270000","e":"OPRA","p":"0.01","cs":"chr","c":"-0.04","cp":"-80.00","b":"-","a":"0.03","oi":"1893","vol":"10","strike":"270.00","expiry":"Sep 16, 2016"},{"cid":"663774558210813","name":"","s":"TSLA160916C00275000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"0.01","a":"0.03","oi":"1124","vol":"-","strike":"275.00","expiry":"Sep 16, 2016"},{"cid":"112668851965328","name":"","s":"TSLA160916C00280000","e":"OPRA","p":"0.02","cs":"chb","c":"0.00","cp":"0.00","b":"0.01","a":"0.03","oi":"9380","vol":"-","strike":"280.00","expiry":"Sep 16, 2016"},{"cid":"23495629926976","name":"","s":"TSLA160916C00285000","e":"OPRA","p":"0.04","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"616","vol":"-","strike":"285.00","expiry":"Sep 16, 2016"},{"cid":"1004365825285358","name":"","s":"TSLA160916C00290000","e":"OPRA","p":"0.03","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.20","oi":"2332","vol":"-","strike":"290.00","expiry":"Sep 16, 2016"},{"cid":"330197077576914","name":"","s":"TSLA160916C00295000","e":"OPRA","p":"0.10","cs":"chb","c":"0.00","cp":"0.00","b":"0.01","a":"0.03","oi":"271","vol":"-","strike":"295.00","expiry":"Sep 16, 2016"},{"cid":"1015720399686345","name":"","s":"TSLA160916C00300000","e":"OPRA","p":"0.01","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"2034","vol":"2","strike":"300.00","expiry":"Sep 16, 2016"},{"cid":"371787846867782","name":"","s":"TSLA160916C00305000","e":"OPRA","p":"0.07","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.13","oi":"191","vol":"-","strike":"305.00","expiry":"Sep 16, 2016"},{"cid":"794756977768746","name":"","s":"TSLA160916C00310000","e":"OPRA","p":"0.06","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.13","oi":"341","vol":"-","strike":"310.00","expiry":"Sep 16, 2016"},{"cid":"589274365602892","name":"","s":"TSLA160916C00315000","e":"OPRA","p":"0.01","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.13","oi":"85","vol":"-","strike":"315.00","expiry":"Sep 16, 2016"},{"cid":"958135383206851","name":"","s":"TSLA160916C00320000","e":"OPRA","p":"0.02","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"449","vol":"-","strike":"320.00","expiry":"Sep 16, 2016"},{"cid":"957518746875187","name":"","s":"TSLA160916C00325000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"174","vol":"-","strike":"325.00","expiry":"Sep 16, 2016"},{"cid":"947410564957569","name":"","s":"TSLA160916C00330000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"0.01","a":"0.02","oi":"254","vol":"-","strike":"330.00","expiry":"Sep 16, 2016"},{"cid":"936370081872094","name":"","s":"TSLA160916C00335000","e":"OPRA","p":"0.08","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"121","vol":"-","strike":"335.00","expiry":"Sep 16, 2016"},{"cid":"869235801270819","name":"","s":"TSLA160916C00340000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"122","vol":"-","strike":"340.00","expiry":"Sep 16, 2016"},{"cid":"784091407817438","name":"","s":"TSLA160916C00345000","e":"OPRA","p":"0.79","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"38","vol":"-","strike":"345.00","expiry":"Sep 16, 2016"},{"cid":"85239239120130","name":"","s":"TSLA160916C00350000","e":"OPRA","p":"0.05","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"454","vol":"-","strike":"350.00","expiry":"Sep 16, 2016"},{"cid":"211447090706369","name":"","s":"TSLA160916C00355000","e":"OPRA","p":"1.93","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"20","vol":"-","strike":"355.00","expiry":"Sep 16, 2016"},{"cid":"351823136572506","name":"","s":"TSLA160916C00360000","e":"OPRA","p":"0.55","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"64","vol":"-","strike":"360.00","expiry":"Sep 16, 2016"},{"cid":"804800293852884","name":"","s":"TSLA160916C00365000","e":"OPRA","p":"1.35","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"118","vol":"-","strike":"365.00","expiry":"Sep 16, 2016"},{"cid":"774749443516921","name":"","s":"TSLA160916C00370000","e":"OPRA","p":"0.23","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"23","vol":"-","strike":"370.00","expiry":"Sep 16, 2016"},{"cid":"62924785666214","name":"","s":"TSLA160916C00375000","e":"OPRA","p":"0.17","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"168","vol":"-","strike":"375.00","expiry":"Sep 16, 2016"},{"cid":"762305391919801","name":"","s":"TSLA160916C00380000","e":"OPRA","p":"0.10","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.13","oi":"89","vol":"-","strike":"380.00","expiry":"Sep 16, 2016"},{"cid":"793017123886757","name":"","s":"TSLA160916C00385000","e":"OPRA","p":"1.45","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"228","vol":"-","strike":"385.00","expiry":"Sep 16, 2016"},{"cid":"826948232988990","name":"","s":"TSLA160916C00390000","e":"OPRA","p":"0.45","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"41","vol":"-","strike":"390.00","expiry":"Sep 16, 2016"},{"cid":"598383802441737","name":"","s":"TSLA160916C00395000","e":"OPRA","p":"0.24","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"20","vol":"-","strike":"395.00","expiry":"Sep 16, 2016"},{"cid":"983900197677305","name":"","s":"TSLA160916C00400000","e":"OPRA","p":"0.02","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"278","vol":"-","strike":"400.00","expiry":"Sep 16, 2016"},{"cid":"322652828621972","name":"","s":"TSLA160916C00410000","e":"OPRA","p":"0.15","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"25","vol":"-","strike":"410.00","expiry":"Sep 16, 2016"},{"cid":"55290337064305","name":"","s":"TSLA160916C00420000","e":"OPRA","p":"0.49","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"48","vol":"-","strike":"420.00","expiry":"Sep 16, 2016"},{"cid":"406767026062965","name":"","s":"TSLA160916C00430000","e":"OPRA","p":"-","c":"-","b":"-","a":"0.03","oi":"0","vol":"-","strike":"430.00","expiry":"Sep 16, 2016"},{"cid":"806365700330173","name":"","s":"TSLA160916C00440000","e":"OPRA","p":"0.84","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"60","vol":"-","strike":"440.00","expiry":"Sep 16, 2016"},{"cid":"225372731645320","name":"","s":"TSLA160916C00450000","e":"OPRA","p":"0.06","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"41","vol":"-","strike":"450.00","expiry":"Sep 16, 2016"},{"cid":"341884545155871","name":"","s":"TSLA160916C00460000","e":"OPRA","p":"0.94","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"29","vol":"-","strike":"460.00","expiry":"Sep 16, 2016"},{"cid":"760487192324210","name":"","s":"TSLA160916C00470000","e":"OPRA","p":"0.20","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"27","vol":"-","strike":"470.00","expiry":"Sep 16, 2016"},{"cid":"211838278250894","name":"","s":"TSLA160916C00480000","e":"OPRA","p":"0.10","cs":"chb","c":"0.00","cp":"0.00","b":"-","a":"0.03","oi":"89","vol":"-","strike":"480.00","expiry":"Sep 16, 2016"}]
但是,我收到错误消息(来自 print
):
JsError(List(((5)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((5)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((6)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((6)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((11)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((11)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((12)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((12)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((14)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((14)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((15)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((15)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((16)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((16)/cs,List(ValidationError(List(error.path.missing),WrappedArray()))), ((82)/cp,List(ValidationError(List(error.path.missing),WrappedArray()))), ((82)/cs,List(ValidationError(List(error.path.missing),WrappedArray())))))
我错过了什么?
编辑:
显然,8/88 个实例中缺少“cp”字段。因为我只对“p”和“strike”字段感兴趣。我将问题更改为:
如何只读取这两个字段(p 和 Strike)?忽略其余部分。
最佳答案
如果您只对“p”和“strike”字段感兴趣,可以使用以下代码:
case class OptionEntry(p: String,
strike: String)
val optionEntries = Json.parse(jsonString)
implicit val optionEntryReads: Reads[OptionEntry] = (
(JsPath \ "p").read[String] and
(JsPath \ "strike").read[String]
)(OptionEntry.apply _)
println(optionEntries.validate[List[OptionEntry]])
所以您不必阅读所有字段。但是如果你想保留字段并且你知道有时会丢失“cp”字段,你可以通过以下代码将其设置为Option
:
case class OptionEntry(cid: String,
name: String,
s: String,
e: String,
p: String,
cs: String,
c: String,
cp: Option[String],
b: String,
a: String,
oi: String,
vol: String,
strike: String,
expiry: String)
val optionEntries = Json.parse(jsonString)
implicit val optionEntryReads: Reads[OptionEntry] = (
(JsPath \ "cid").read[String] and
(JsPath \ "name").read[String] and
(JsPath \ "s").read[String] and
(JsPath \ "e").read[String] and
(JsPath \ "p").read[String] and
(JsPath \ "cs").read[String] and
(JsPath \ "c").read[String] and
(JsPath \ "cp").readNullable[String] and
(JsPath \ "b").read[String] and
(JsPath \ "a").read[String] and
(JsPath \ "oi").read[String] and
(JsPath \ "vol").read[String] and
(JsPath \ "strike").read[String] and
(JsPath \ "expiry").read[String]
)(OptionEntry.apply _)
println(optionEntries.validate[List[OptionEntry]])
关于json - Play Json 中的验证错误(路径丢失),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39347050/
我想做的是让 JTextPane 在 JPanel 中占用尽可能多的空间。对于我使用的 UpdateInfoPanel: public class UpdateInfoPanel extends JP
我在 JPanel 中有一个 JTextArea,我想将其与 JScrollPane 一起使用。我正在使用 GridBagLayout。当我运行它时,框架似乎为 JScrollPane 腾出了空间,但
我想在 xcode 中实现以下功能。 我有一个 View Controller 。在这个 UIViewController 中,我有一个 UITabBar。它们下面是一个 UIView。将 UITab
有谁知道Firebird 2.5有没有类似于SQL中“STUFF”函数的功能? 我有一个包含父用户记录的表,另一个表包含与父相关的子用户记录。我希望能够提取用户拥有的“ROLES”的逗号分隔字符串,而
我想使用 JSON 作为 mirth channel 的输入和输出,例如详细信息保存在数据库中或创建 HL7 消息。 简而言之,输入为 JSON 解析它并输出为任何格式。 最佳答案 var objec
通常我会使用 R 并执行 merge.by,但这个文件似乎太大了,部门中的任何一台计算机都无法处理它! (任何从事遗传学工作的人的附加信息)本质上,插补似乎删除了 snp ID 的 rs 数字,我只剩
我有一个以前可能被问过的问题,但我很难找到正确的描述。我希望有人能帮助我。 在下面的代码中,我设置了varprice,我想添加javascript变量accu_id以通过rails在我的数据库中查找记
我有一个简单的 SVG 文件,在 Firefox 中可以正常查看 - 它的一些包装文本使用 foreignObject 包含一些 HTML - 文本包装在 div 中:
所以我正在为学校编写一个 Ruby 程序,如果某个值是 1 或 3,则将 bool 值更改为 true,如果是 0 或 2,则更改为 false。由于我有 Java 背景,所以我认为这段代码应该有效:
我做了什么: 我在这些账户之间创建了 VPC 对等连接 互联网网关也连接到每个 VPC 还配置了路由表(以允许来自双方的流量) 情况1: 当这两个 VPC 在同一个账户中时,我成功测试了从另一个 La
我有一个名为 contacts 的表: user_id contact_id 10294 10295 10294 10293 10293 10294 102
我正在使用 Magento 中的新模板。为避免重复代码,我想为每个产品预览使用相同的子模板。 特别是我做了这样一个展示: $products = Mage::getModel('catalog/pro
“for”是否总是检查协议(protocol)中定义的每个函数中第一个参数的类型? 编辑(改写): 当协议(protocol)方法只有一个参数时,根据该单个参数的类型(直接或任意)找到实现。当协议(p
我想从我的 PHP 代码中调用 JavaScript 函数。我通过使用以下方法实现了这一点: echo ' drawChart($id); '; 这工作正常,但我想从我的 PHP 代码中获取数据,我使
这个问题已经有答案了: Event binding on dynamically created elements? (23 个回答) 已关闭 5 年前。 我有一个动态表单,我想在其中附加一些其他 h
我正在尝试找到一种解决方案,以在 componentDidMount 中的映射项上使用 setState。 我正在使用 GraphQL连同 Gatsby返回许多 data 项目,但要求在特定的 pat
我在 ScrollView 中有一个 View 。只要用户按住该 View ,我想每 80 毫秒调用一次方法。这是我已经实现的: final Runnable vibrate = new Runnab
我用 jni 开发了一个 android 应用程序。我在 GetStringUTFChars 的 dvmDecodeIndirectRef 中得到了一个 dvmabort。我只中止了一次。 为什么会这
当我到达我的 Activity 时,我调用 FragmentPagerAdapter 来处理我的不同选项卡。在我的一个选项卡中,我想显示一个 RecyclerView,但他从未出现过,有了断点,我看到
当我按下 Activity 中的按钮时,会弹出一个 DialogFragment。在对话框 fragment 中,有一个看起来像普通 ListView 的 RecyclerView。 我想要的行为是当
我是一名优秀的程序员,十分优秀!