Coder Social home page Coder Social logo

cn1json's Introduction

Codename One JSON Library

A library to read and write JSON in Codename One

Synopsis

This library is a port of this J2ME JSON library so that it can be used in Codename One. Only minor changes have been made in order to improve performance.

Codename One already includes a JSON parser, so why package up another library? One reason is for pure variety. The interface of this library is different than the built-in CN1 parser and this might be preferrable to some. Another reason is that it is easy to use this library outside of Codename One. If I'm writing code that I want to reuse in CN1 and other Java environments, I might choose to use this library for portability.

License

Apache License 2.0

Requirements

  1. Codename One 1.0 or higher

Installation

  1. Download the CN1JSON.cn1lib file and copy it into your Codename One Application's "lib" directory.
  2. Right click on your application's icon in the Netbeans project explorer, and select "Refresh Libs"

Usage Examples


        JSONObject index = new JSONObject(myJSONString);
        tour.setTourId(index.getInt("tour_id"));
        tour.setName(index.getString("tour_name"));
        
        JSONArray dests = index.getJSONArray("destinations");
        Map<String,SoundFile> audioFileIndex = new HashMap<String,SoundFile>();
        for ( int i=0; i<dests.length(); i++){
            JSONObject dest = dests.getJSONObject(i);
            PointOfInterest poi = new PointOfInterest();
            poi.setId(dest.getInt("tour_destination_id"));
            poi.setName(dest.getString("destination_name"));
            poi.setDescription(dest.getString("destination_description"));
            
            SoundFile sf = new SoundFile();
            sf.setStorageKey("poi:"+poi.getId());
            sf.setMimetype(dest.getString("audio_file_mimetype"));
            poi.setSoundFile(sf);
            audioFileIndex.put(dest.getString("audio_file"), sf);
            tour.addPointOfInterest(poi);
            
        }

You can find other usage examples on the J2ME-JSON site.

Credits

  1. Library ported packaged by Steve Hannah
  2. Original JTar Library by Greyson

cn1json's People

Contributors

shannah avatar

Watchers

 avatar  avatar

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.