android.util.JsonWriter#close ( )源码实例Demo

下面列出了android.util.JsonWriter#close ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: NClientV2   文件: GeneralPreferenceFragment.java
private String getDataSettings(Context context)throws IOException{
    String[]names=new String[]{"Settings","ScrapedTags"};
    StringWriter sw=new StringWriter();
    JsonWriter writer=new JsonWriter(sw);
    writer.setIndent("\t");

    writer.beginObject();
    for(String name:names)
        processSharedFromName(writer,context,name);
    writer.endObject();

    writer.flush();
    String settings=sw.toString();
    writer.close();

    LogUtility.d(settings);
    return settings;
}
 
源代码2 项目: cwac-saferoom   文件: TypeTransmogrifier.java
@TypeConverter
public static String fromStringSet(Set<String> strings) {
  if (strings==null) {
    return(null);
  }

  StringWriter result=new StringWriter();
  JsonWriter json=new JsonWriter(result);

  try {
    json.beginArray();

    for (String s : strings) {
      json.value(s);
    }

    json.endArray();
    json.close();
  }
  catch (IOException e) {
    Log.e(TAG, "Exception creating JSON", e);
  }

  return(result.toString());
}
 
源代码3 项目: androdns   文件: SessionStorage.java
public static void save(Context context, String filename, ArrayList<Session> sessions) {
    try {

        FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE);

        JsonWriter writer = new JsonWriter(new OutputStreamWriter(fos, "UTF-8"));
        writer.setIndent("  ");
        writer.beginArray();
        for (Session s : sessions) {
            s.toJSON(writer);
        }
        writer.endArray();
        writer.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}