jsonobject

scala map,flatmap,filter的用法

大憨熊 提交于 2019-11-26 06:33:52
例子: object test extends App { val fruits = Seq( "apple" , "banana" , "orange" ) println(fruits.map(_.toUpperCase)) println(fruits.flatMap(_.toUpperCase)) } 输出: List (APPLE, BANANA, ORANGE) List (A, P, P, L, E , B, A, N , A, N , A, O , R, A, N , G, E ) 例子: object test extends App { def toInt(s: String): Option[Int] = { try { Some(Integer.parseInt(s.trim)) } catch { // catch Exception to catch null 's' case e: Exception => None } } val strings = Seq( "1" , "2" , "foo" , "3" , "bar" ) println(strings.map(toInt)) println(strings.flatMap(toInt)) } 输出: List( Some( 1 ) , Some( 2 ) , None, Some( 3 ) ,

convert ArrayList<MyCustomClass> to JSONArray

微笑、不失礼 提交于 2019-11-26 05:16:09
问题 I have an ArrayList that I use within an ArrayAdapter for a ListView. I need to take the items in the list and convert them to a JSONArray to send to an API. I\'ve searched around, but haven\'t found anything that explains how this might work, any help would be appreciated. UPDATE - SOLUTION Here is what I ended up doing to solve the issue. Object in ArrayList: public class ListItem { private long _masterId; private String _name; private long _category; public ListItem(long masterId, String

Volley JsonObjectRequest Post parameters no longer work

本小妞迷上赌 提交于 2019-11-26 04:25:09
问题 I am trying to send POST parameters in a Volley JsonObjectRequest. Initially, it was working for me by following what the official code says to do of passing a JSONObject containing the parameters in the constructor of the JsonObjectRequest. Then all of a sudden it stopped working and I haven\'t made any changes to the code that was previously working. The server no longer recognizes that any POST parameters are being sent. Here is my code: RequestQueue queue = Volley.newRequestQueue(this);