简体   繁体   English

Json编码的关联数组(来自PHP)在Java中转换为json对象

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

I have a json encoded associative array which contains a combination of map and list this is done in PHP. 我有一个json编码的关联数组,其中包含map和list的组合,这是在PHP中完成的。

This json string is transferred to java via web service call 该json字符串通过Web服务调用传输到Java

How do I handle this json string to get the original associative array data. 我如何处理此json字符串以获取原始的关联数组数据。 I know java doesn't support associative array. 我知道Java不支持关联数组。 But any alternatives are appreciated. 但是任何替代方案都值得赞赏。

Sample json string: 样本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"]
                    }
                }
            }
        }
    }
}

Use javax.jason 使用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