-4

BlackBerry で JSON データを解析するには? 次のデータを解析するには助けが必要です。

{
    "menu": {
        "id": "Home",
        "menuitem": [
            {
                "type": "form",
                "name": "Order",
                "url": "http://domain/oredr.aspx",
                "Row": [
                    {
                        "Index": "1",
                        "Control": [
                            {
                                "type": "LB",
                                "align": "Left",
                                "send": "No",
                                "value": "User Name"
                            },
                            {
                                "type": "TB",
                                "align": "Right",
                                "send": "Yes",
                                "param": "username",
                                "maxlength": "25",
                                "ctype": "Alpha"
                            }
                        ]
                    },
                    {
                        "Index": "2",
                        "Control": [
                            {
                                "type": "LB",
                                "align": "Left",
                                "send": "No",
                                "value": "Mobile No"
                            },
                            {
                                "type": "TB",
                                "align": "Right",
                                "send": "Yes",
                                "param": "MobileNo",
                                "maxlength": "10",
                                "ctype": "Numeric"
                            }
                        ]
                    },
                    {
                        "Index": "3",
                        "Control": [
                            {
                                "type": "LB",
                                "align": "Left",
                                "send": "No",
                                "value": "Email ID"
                            },
                            {
                                "type": "TB",
                                "align": "Right",
                                "send": "Yes",
                                "param": "email",
                                "maxlength": "50",
                                "ctype": "Email"
                            }
                        ]
                    },
                    {
                        "Index": "4",
                        "Control": [
                            {
                                "type": "None",
                                "align": "Left",
                                "send": "No"
                            },
                            {
                                "type": "BT",
                                "align": "Center",
                                "send": "No",
                                "value": "Submit",
                                "ctype": "Submit"
                            }
                        ]
                    }
                ]
            },
            {
                "type": "form",
                "value": "Stock",
                "url": "http://domain/stock.aspx",
                "Row": [
                    {
                        "Index": "1",
                        "Control": [
                            {
                                "type": "LB",
                                "align": "Left",
                                "send": "No",
                                "value": "Select Medium"
                            },
                            {
                                "type": "CB",
                                "align": "Right",
                                "send": "Yes",
                                "param": "medium",
                                "Item": [
                                    {
                                        "name": "Yes"
                                    },
                                    {
                                        "name": "No"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "Index": "2",
                        "Control": [
                            {
                                "type": "None",
                                "align": "Left",
                                "send": "No"
                            },
                            {
                                "type": "BT",
                                "align": "Center",
                                "send": "No",
                                "value": "Submit",
                                "ctype": "Submit"
                            }
                        ]
                    }
                ]
            },
            {
                "type": "form",
                "value": "Custom",
                "url": "http://domain/custom.aspx",
                "Row": [
                    {
                        "Index": "1",
                        "Control": [
                            {
                                "type": "LB",
                                "align": "Left",
                                "send": "No",
                                "value": "Offer Type"
                            },
                            {
                                "type": "DD",
                                "align": "Right",
                                "send": "Yes",
                                "param": "offertype",
                                "Item": [
                                    {
                                        "name": "Marketing"
                                    },
                                    {
                                        "name": "Promotional"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "Index": "2",
                        "Control": [
                            {
                                "type": "None",
                                "align": "Left",
                                "send": "No"
                            },
                            {
                                "type": "BT",
                                "align": "Center",
                                "send": "No",
                                "value": "Submit",
                                "ctype": "Submit"
                            }
                        ]
                    }
                ]
            }
        ]
    }
}
4

1 に答える 1

3

最初にこのリンクを参照してください - json

これを試してください - 最初に json パーサーの .jar ファイルをダウンロードし、それをプロジェクトにインポートします。

JSONObject data = new JSONObject(data);
JSONObject menu = data.getJSONObject("menu");

Stringフィールドの値を取得するには、次のコードを使用します -

String id = menu.getString("id");
JSONObject menuitem = json.getJSONObject("menuitem");

等々。

于 2012-06-08T08:34:54.573 に答える