2

I am trying to convert this XML file/ or any XML file to JSON object.

<classes>
    <class>
        <name>MORN CS</name>
        <subjects>
            <subject>
                <title>COM101</title>
                <lessons>
                    <lesson>
                        <header>Basic</header>
                        <desc>Insert description here</desc>
                    </lesson> 
                    <lesson>
                        <header>Intros</header>
                        <desc>lorem ipsum </desc>
                    </lesson>
                </lessons>
            </subject>
        </subjects>
     </class>
</classes>

I have tried the code in this link but i have no idea to implement it using JDOM and its result is not the same on the xml file. Convert xml file to json object using dom parser in java This is the result

{
"classes": [
    {
        "class": [
            {
                "subjects": [
                    {
                        "subject": [
                            {
                                "title": "COM101",
                                "lessons": [
                                    {
                                        "lesson": [
                                            {
                                                "header": "Intros",
                                                "desc": "lorem ipsum "
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ],
                "name": "MORN CS"
            }
        ]
    }
]}

Well my question is how could I convert my xml file to an JSONObject in Java?? Could someone give me idea or any help is much appreciated.

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.