0

J2me Blackberry でこの JSON を作成しようとしています。私は試しましたが、それを行う方法がわかりません。これは私が取り組んでいるコードです。

JSONObject jArray= new JSONObject();
JSONObject jObjectData = new JSONObject();

    try { 
          jObjectData.put("name", name);
          jObjectData.put("scaleItems", 2); 
          jArray.accumulate("friends",jObjectData);
        } 
       catch (JSONException e) {
                    // TODO Auto-generated catch block
                       e.printStackTrace();
                      }

以下は、私が達成しようとしているJsonです。

 {
        "newScale": {
            "name": "scaleName",
            "scaleitems": [
                {
                    "name": "option 1"
                },
                {
                    "name": "option 2"
                },
                {
                    "name": "option 3"
                },
                {
                    "name": "option 4"
                },
                {
                    "name": "option 5"
                },
                {
                    "name": "option 6"
                }
            ]
        }
    }
4

1 に答える 1

0

それを String Buffer に追加しました。

String Buffer rjson = new StringBuffer("{ \"groupid\": \"" + groupId
                                + "\",");
                        rjson.append("\"question\": \"" + questionArea.getText()
                                + "\",");
                        rjson.append("\"hasComment\": \""
                                + checkBoxComments.getChecked() + "\",");
                        rjson.append("\"endDate\": \"" + fromTo.getText() + "\",");
                        rjson.append("\"newScale\":{");
                        rjson.append("\"name\": \"customName\",");
                        rjson.append("\"scaleItems\": [");

                        rjson.append("{");
                        rjson.append("\"name\": \"" + Option1.getText() + "\" ");
                        rjson.append("},");

                        rjson.append("{");
                        rjson.append("\"name\": \"" + Option2.getText() + "\" ");
                        rjson.append("},");

                        rjson.append("{");
                        rjson.append("\"name\": \"" + Option3.getText() + "\" ");
                        rjson.append("},");

                        rjson.append("{");
                        rjson.append("\"name\": \"" + Option4.getText() + "\" ");
                        rjson.append("},");

                        rjson.append("{");
                        rjson.append("\"name\": \"" + Option5.getText() + "\" ");
                        rjson.append("},");

                        rjson.append("{");
                        rjson.append("\"name\": \"" + Option6.getText() + "\" ");
                        rjson.append("}");

                        rjson.append("]}}");
于 2013-02-12T12:05:43.807 に答える