简体   繁体   English

在Android / Java中创建结构JSON

[英]Create Structure JSON in Android/Java

I would like to do: 我想要做:

(Object)Date:
    (Object)HomeTeam:
        (Array)Name
        (Array)Num
    (Object)AwayTeam:
        (Array)Name
        (Array)Num
(Object)Date:
    (Object)HomeTeam:
        (Array)Name
        (Array)Num
    (Object)AwayTeam:
        (Array)Name
        (Array)Num
(Object)Date:
    (Object)HomeTeam:
        (Array)Name
        (Array)Num
    (Object)AwayTeam:
        (Array)Name
        (Array)Num

So far, I tried to: 到目前为止,我试图:

JSONObject json = new JSONObject(); 
JSONObject home = new JSONObject();
JSONObject away = new JSONObject();
json.put("Date", xxx);  I dun know how to do
json.put("HomeTeam", home); 
json.put("AwayTeam", away);   

And there are many date object, please help.. 并且有很多约会对象,请帮忙。

YOu can do this with bundled JSON lib. 您可以使用捆绑的JSON库实现此目的。 To get this struct: 要获得此结构:

(Object)Date:
    (Object)HomeTeam:
        (Array)Name
        (Array)Num

you do JSONObject date = new JSONObject(); 您执行JSONObject date = new JSONObject();

JSONObject team = new JSONObject();
  team.put("Name", new JSONArray());
  team.put("Name", new JSONArray());
date.put("id", team);

Not that "id" should rather be different per node, or you should switch to JSONArray there. 并不是每个节点的"id"都应该不同,否则您应该在那里切换到JSONArray。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM