Back to project page joanne.
The source code is released under:
GNU General Public License
If you think the Android project joanne listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.gmail.altakey.joanne.util; /* w w w. jav a2 s . c o m*/ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONTokener; import java.util.HashSet; import java.util.Set; public class IdListCoder { public String encode(Set<Long> list) { final JSONArray array = new JSONArray(); for (Long id : list) { array.put(id); } return array.toString(); } public Set<Long> decode(final String data) { final Set<Long> ret = new HashSet<Long>(); try { final JSONArray friends = (JSONArray)new JSONTokener(data).nextValue(); for (int i=0; i<friends.length(); ++i) { try { ret.add(friends.getLong(i)); } catch (JSONException e) { } } } catch (final JSONException e) { } catch (final ClassCastException e) { } return ret; } }