I'm sorry I don't understand your question. I'm not sure I understand where you'd be using a for, while loop.
I just realized you really don't need to specify ArrayList in the use() method because it defaults to ArrayList. However, you do need to specify Long as the values of the array because it defaults to Integer for JSON numbers. Try this example and maybe it will answer your question:
String episodeIds = "[ 1, 2, 3, 4, 5 ] ";
List<Long> list = new JSONDeserializer<List<Long>>().use("values", Long.class).deserialize( episodeIds );
System.out.println( list );
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
i tryed, but it is dont work. With it i get null pointer Ex.
If i change array and insert there values - {"values":} i get another Ex. I solved my problem another way but still interrested how to solve it with deserializer. Thanks a lot.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
List<long> list = new JSONDeserializer<list\<long>>().use(null, ArrayList.class).use("values", Long.class).deserialize( episodeIds );
System.out.println( list );</list\<long></long>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
String episodeIds = "['abc', '123', '456']";
List<long> list = new JSONDeserializer<arraylist\<long>>().use(null, ArrayList.class).deserialize(episodeIds);
System.out.println(list);</arraylist\<long></long>
Using this code I think I must get a List<Long>, but it is don't work. What i do wrong? can you help me please
Sorry..
String episodeIds = "";
List<Long> list = new JSONDeserializer<ArrayList<Long>>().use(null, ArrayList.class).deserialize(episodeIds);
System.out.println(list);
Using this code I think I must get a List, but it is don't work. What i do wrong? can you help me please
You don't have a json object in the episodeIds.
Try this:
Charlie
But if I have not simple String. For Example List<String> to List<Long>? How can i do it without using for,while etc.
I'm sorry I don't understand your question. I'm not sure I understand where you'd be using a for, while loop.
I just realized you really don't need to specify ArrayList in the use() method because it defaults to ArrayList. However, you do need to specify Long as the values of the array because it defaults to Integer for JSON numbers. Try this example and maybe it will answer your question:
i tryed, but it is dont work. With it i get null pointer Ex.
If i change array and insert there values - {"values":} i get another Ex. I solved my problem another way but still interrested how to solve it with deserializer. Thanks a lot.
I ran this exact code and it worked without a problem. Do you have the latest version?
flexjson 1.9.2
i tested exatly this code and got a null pointer exeption
under 1.9.2
List<long> list = new JSONDeserializer<list\<long>>().use(null, ArrayList.class).use("values", Long.class).deserialize( episodeIds );
System.out.println( list );</list\<long></long>
I just taked from repository flexjson 2 and raned this example. All is working fine