簡體   English   中英

Json編碼的關聯數組(來自PHP)在Java中轉換為json對象

[英]Json encoded associative array (from PHP) convert to json object in java

我有一個json編碼的關聯數組,其中包含map和list的組合,這是在PHP中完成的。

該json字符串通過Web服務調用傳輸到Java

我如何處理此json字符串以獲取原始的關聯數組數據。 我知道Java不支持關聯數組。 但是任何替代方案都值得贊賞。

樣本json字符串:

{
    "seminar_info":{
        "seminar_id":"3485",
        "seminar_name":"Importance of breast-feeding Seminar",
        "start_date":"10\/20\/2015",
        "end_date":"10\/22\/2015",
        "venue":"Watefront Hotel",
        "schedules":{
            "2531":{
                "date-title":"12\/20 Introduction to breastfeeding",
                "classes":{
                    "4857":{
                        "detail":"10:00-12:00 Importance of breast feeding",
                        "points":"16"
                    },
                    "4858":{
                        "detail":"13:00-15:00 Myths of formula solutions",
                        "points":"10"
                    },
                    "4859":{
                        "detail":"16:00-18:00 What we should know about Breast feeding",
                        "points":"10"
                    }
                },
                "meals":{
                    "4756":"Happy meal set",
                    "4757":"Healthy all veggie meal set",
                    "4758":"All pork set"
                }
            },
            "2532":{
                "date-title":"12\/21 Breastfeeding long term impacts to mother and child",
                "classes":{
                    "4860":{
                        "detail":"10:00-12:00 The healthy parent pt1",
                        "points":"12"
                    },
                    "4861":{
                        "detail":"13:00-15:00 The healthy parent pt2",
                        "points":"9"
                    }
                },
                "meals":{
                    "4756":"Happy meal set",
                    "4757":"Healthy all veggie meal set",
                    "4758":"All pork set"
                }
            }
        },
        "books":{
            "9671":{
                "book_name":"Ideas for Dr. Kitamura",
                "description":"Everything about life and breast feeding"
            }
        },
        "products":{
            "9672":{
                "product_name":"lanex tshirt",
                "description":"tshirt of lanex"
            }
        }
    },
    "participants":{
        "2130":{
            "name":"Galapate, Raymund",
            "emailad":"chuvaness@gmail.com",
            "lecturer_flag":"true",
            "sequence_num":"1",
            "seminar_info":{
                "schedules_checked":{
                    "2531":{
                        "classes":["4857","4858","4859"],
                        "children_info":{
                            "age_three":"1",
                            "age_others":"2",
                            "children_accompany_val":"Available",
                            "separate_child_val":"Nothing",
                            "parent_child_room_val":"Yes",
                            "parent_child_space_val":"Yes",
                            "child_info":"Child1, Child2, Child3",
                            "attendant":"accompany1",
                            "note":"Child1 is abnormal"
                        },
                        "meals":["4756","4757"]
                    },"2532":{
                        "classes":["4857"],
                        "meals":["4756"]
                    }
                },
                "books":{
                    "9671":"1"
                },
                "products":{
                    "9672":"2"
                }
            }
        },
        "2131":{
            "name":"Caruana, AC",
            "emailad":"acgurl@gmail.com",
            "lecturer_flag":"false",
            "sequence_num":"2",
            "seminar_info":{
                "schedules_checked":{
                    "2531":{
                        "classes":["4857","4858","4859"],
                        "meals":["4756","4757"]
                    }
                }
            }
        }
    }
}

使用javax.jason

try (JsonReader jsonReader = Json.createReader(new StringReader(jsonString))) {
    JsonObject object = jsonReader.readObject();
    System.out.println(object);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM