Convert a JSON string to object in Java ME?

前端 未结 14 949
有刺的猬
有刺的猬 2020-11-22 02:12

Is there a way in Java/J2ME to convert a string, such as:

{name:\"MyNode\", width:200, height:100}

to an internal Object representation of

14条回答
  •  误落风尘
    2020-11-22 03:01

    You have many JSON parsers for Java:

    • JSONObject.java
      A JSONObject is an unordered collection of name/value pairs. Its external form is a string wrapped in curly braces with colons between the names and values, and commas between the values and names. The internal form is an object having get() and opt() methods for accessing the values by name, and put() methods for adding or replacing values by name. The values can be any of these types: Boolean, JSONArray, JSONObject, Number, and String, or the JSONObject.NULL object.

    • JSONArray.java
      A JSONArray is an ordered sequence of values. Its external form is a string wrapped in square brackets with commas between the values. The internal form is an object having get() and opt() methods for accessing the values by index, and put() methods for adding or replacing values. The values can be any of these types: Boolean, JSONArray, JSONObject, Number, and String, or the JSONObject.NULL object.

    • JSONStringer.java
      A JSONStringer is a tool for rapidly producing JSON text.

    • JSONWriter.java
      A JSONWriter is a tool for rapidly writing JSON text to streams.

    • JSONTokener.java
      A JSONTokener takes a source string and extracts characters and tokens from it. It is used by the JSONObject and JSONArray constructors to parse JSON source strings.

    • JSONException.java
      A JSONException is thrown when a syntax or procedural error is detected.

    • JSONString.java
      The JSONString is an interface that allows classes to implement their JSON serialization.

提交回复
热议问题