将复杂的嵌套JSON反序列化为Scala对象(Deserializing complex nested JSON into Scala objects)
斯卡拉2.12在这里。 我试图使用Lift-JSON将一些JSON反序列化为Scala对象,并且在导航Lift API时遇到问题。 请注意:我没有与Lift-JSON结婚,只要我不需要将任何重要的/核心的Play依赖关系带入我的项目,任何其他工作解决方案都将被接受。
这里是我试图阅读的JSON文件:
{ "fizz" : "buzz", "foo" : [ "123", "456", "789" ], "bar" : { "whistle" : 1, "feather" : true } }
这是我的Scala对象层次结构:
case class Bar(whistle : Integer, feather : Boolean) case class MyConfig(fizz : String, foo : Array[String], bar : Bar)
最后我对这个代码的最佳尝试:
def loadConfig(configFilePath : String) : MyConfig = { val configJson = Source.fromFile(configFilePath) val parsedJson = parse(configJson.mkString) MyConfig(???) }
我需要进行验证,以便在JSON无效的情况下抛出异常。 任何想法如何从
parsedJson
提取字段并使用它们为我的MyConfig
实例设置值? 以及如何执行验证?Scala 2.12 here. I'm trying to use Lift-JSON to deserialize some JSON into a Scala object and am having trouble navigating the Lift API. Please note: I'm not married to Lift-JSON, any other working solution will be accepted so long as I don't have to bring any heavy/core Play dependencies into my project.
Here's the JSON file I'm trying to read:
{ "fizz" : "buzz", "foo" : [ "123", "456", "789" ], "bar" : { "whistle" : 1, "feather" : true } }
Here's my Scala object hierarchy:
case class Bar(whistle : Integer, feather : Boolean) case class MyConfig(fizz : String, foo : Array[String], bar : Bar)
And finally my best attempt at the codeup for this:
def loadConfig(configFilePath : String) : MyConfig = { val configJson = Source.fromFile(configFilePath) val parsedJson = parse(configJson.mkString) MyConfig(???) }
I need validation in place so that if the JSON is not valid an exception is thrown. Any ideas how I can extract fields out of
parsedJson
and use them to set values for myMyConfig
instance? And how to perform the validation?
原文:https://stackoverflow.com/questions/50355225
最满意答案
试试这样:
$(function(){ $('li.expanded > ul').hide(); $('li.expanded > a').click(function(){ $('li.expanded > ul').not(':hidden').slideToggle(); $(this).next().slideToggle(); }); });
Try it like this:
$(function(){ $('li.expanded > ul').hide(); $('li.expanded > a').click(function(){ $('li.expanded > ul').not(':hidden').slideToggle(); $(this).next().slideToggle(); }); });
相关问答
更多-
如果我理解正确,你想在折叠条上有三个相等的列,对吧? 看看这个小提琴: http : //jsfiddle.net/victmo/f2Scp/我想你忘了添加display:block到你的栏或列。 干杯 If I understand correctly, you want to have three equal columns on your collapse bars, right? Take a look at this fiddle: http://jsfiddle.net/victmo/f2Scp ...
-
你这样做会比以前更加复杂。 如果您只想让其中一个向下滑动而其他人向后滑动,请使用以下代码... $('.accordion-toggler').click(function() { var targetElement = $(this).next('.mod-content'); targetElement.slideToggle(); targetElement.siblings('.mod-content').slideUp(); }); You're making this ...
-
隔离不是当前标题的标题如下所示: $('.accordion-item .heading').not(this).find('.plus-minus-toggle').addClass('collapsed') DEMO Isolate the headings that aren't the current one something like: $('.accordion-item .heading').not(this).find('.plus-minus-toggle').addClass('co ...
-
折叠Jquery手风琴(Collapse Jquery Accordion)[2023-05-25]
它会立即再次打开,因为这是您的代码所要做的 allPanels.slideUp(); // Hide the panel $(this).parent().next().slideDown(); //Show it again 用这些线代替 allPanels.not(this).slideUp(); //hide only ones that aint this one. $(this).parent().next().slideToggle(); //show or hide based on cur ... -
不要使用slideToggle() ,而是使用slideUp() ;) SlideToggel将滑动向上的东西和所有向下的东西。 你希望一切都向上滑动,所以使用slideUp() 编辑 :我修改了你的jsfiddle,并让它工作。 当用户点击“全部显示”按钮时,它将检查文本是什么。 所以在这种情况下'show all',它将全部slideDown。 然后它将文本更改为“隐藏所有”。 如果用户点击“全部隐藏”,它将全部滑动。 如果你在这种情况下使用slideToggle,它也会起作用但是如果用户点击一个问题标 ...
-
//Initialize a accordion with the collapsible option specified. $( ".selector" ).accordion({ collapsible: true }); //Get or set the collapsible option, after init. //getter var collapsible = $( ".selector" ).accordion( "option", "collapsible" ); //setter $ ...
-
试试这样: $(function(){ $('li.expanded > ul').hide(); $('li.expanded > a').click(function(){ $('li.expanded > ul').not(':hidden').slideToggle(); $(this).next().slideToggle(); }); }); Try it like this: ...
-
有这样的工作吗? http://jsfiddle.net/UUhMa/ http://jsfiddle.net/UUhMa/3/ (没有foreach) JS $('#openAll').on('click', function() { $('.openMe').each(function() { var coll = $(this); coll.trigger('expand'); }); }); $('#closeAll').on('click', fun ...
-
您可以将放在HEADER-div中,并将保持为该HEADER的直接兄弟。 例如:
My blog post title
< ...如何通过单击打开和折叠手风琴Jquery(How to open and collapse the same JQuery accordion with click on it only)[2023-05-09]
我创造了一个新的小提琴与一些CSS ... HTMLHeading 1Content 1相关文章
更多- Guava Objects类详解
- 怎么递归json嵌套json?
- scala下载与安装
- Solr的Scala客户端(scalikesolr)介绍
- Scala定义变量
- Scala函数定义与调用
- JSON部分序列化(二)
- scala数组操作
- Json.Net学习笔记
- 使用Intellij IDEA创建scala工程
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)