X Tutup
Skip to content

XML.toString() with key "content" #286

@djoerd

Description

@djoerd

The XML.toString() function seems to ignore keys when they are called "content", strange but true...(?)

import org.json.JSONObject;
import org.json.XML;

public class JSONbug {

    private static void test(String jsonString) {
        JSONObject json = new JSONObject(jsonString);
        System.out.print("Given the JSON object:");
        System.out.println(json);
        System.out.print("which has the keys: ");
        System.out.println(json.keySet());
        System.out.println("If we convert to XML, we get: ");
        System.out.println(XML.toString(json));
    }

    public static void main( String[] args ) {
        System.out.println("Test 1: If a JSON key is 'content', things break:");
        test("{\"content\": \"test this\", \"status\": \"error\"}");
        // test this<status>ok</status>
        System.out.println("-----------------");
        System.out.println("Test 2: keys like 'contents' work fine:");
        test("{\"contents\": \"test this\", \"status\": \"ok\"}");
        // <contents>test this</contents><status>ok</status>
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup