Giter Site home page Giter Site logo

android-write-and-read-json's Introduction

Android-Write-Read-JSON-Basic

JsonWriter and JsonReader , No Library

JsonWriter

try{
    JsonWriter jsonWriter = new JsonWriter(
      new OutputStreamWriter(openFileOutput("data.json" , MODE_PRIVATE)));
    try{
        jsonWriter.setIndent("  ");

        jsonWriter.beginObject();
        jsonWriter.name("name");
        jsonWriter.value("Kocthaphan Muangsan");
        jsonWriter.name("email");
        jsonWriter.value("[email protected]");
        jsonWriter.endObject();
    }finally {
        jsonWriter.close();
    }
}catch (IOException ex){
    ex.printStackTrace();
}

JsonReader

try{
     JsonReader jsonReader = new JsonReader(new InputStreamReader((openFileInput("data.json"))));
      try{
          jsonReader.beginObject();

          while (jsonReader.hasNext()){
              String name = jsonReader.nextName();
              if("name".equals(name)){
                  txtName.setText(jsonReader.nextString());
              }else if("email".equals(name)){
                  txtValue.setText(jsonReader.nextString());
               }else{
                  //Unkhonw attribute
                  jsonReader.skipValue();
               }
          }
          jsonReader.endObject();
      }finally {
          jsonReader.close();
      }
}catch (IOException e){
     e.printStackTrace();
}

android-write-and-read-json's People

Contributors

werockstar avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

shihabmi7

android-write-and-read-json's Issues

i can not use openFileOutput

Hello sir, when i try to use in different class(not main)

JsonWriter jsonWriter = new JsonWriter(
new OutputStreamWriter(getActivity().openFileOutput("data.json" ,getActivity().MODE_PRIVATE)));

that shows me CANNOT RESOLVE METHOD
image

What is your suggest for me? thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.