2013-02-09 100 views
0

我想在J2me Blackberry中製作這個JSON。我嘗試過,但我沒有得到如何去做。 這是我正在處理的代碼。黑莓寫作JSON

​​

而下面是我試圖實現的Json。

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

回答

0

那麼我只是將它附加到字符串緩衝區。

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("]}}");