How would I express XML tag attributes in JSON?

后端 未结 13 2232
遥遥无期
遥遥无期 2020-12-07 20:35

I am designing an API for my webapp.

I was thinking to support only JSON responses (not XML) because more streamlined.

But I have just bumped to this XML:

13条回答
  •  余生分开走
    2020-12-07 21:37

    Could be compact in the JSON too, attribute is just the same as the value inside tag

    from here:

    http://www.json.org/example.html

    {"widget": {
        "debug": "on",
        "window": {
            "title": "Sample Konfabulator Widget",
            "name": "main_window",
            "width": 500,
            "height": 500
        },
        "image": { 
            "src": "Images/Sun.png",
            "name": "sun1",
            "hOffset": 250,
            "vOffset": 250,
            "alignment": "center"
        }
    }}  
    

    The same text expressed as XML:

    
        on
        
            main_window
            500
            500
        
        
            250
            250
            center
        
    
    

提交回复
热议问题