Click here to Skip to main content
15,896,154 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Rhetorical Question Pin
CodeWraith5-Nov-18 0:38
CodeWraith5-Nov-18 0:38 
GeneralRe: Rhetorical Question Pin
Michael Martin5-Nov-18 0:48
professionalMichael Martin5-Nov-18 0:48 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 0:52
Super Lloyd5-Nov-18 0:52 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 0:51
Super Lloyd5-Nov-18 0:51 
GeneralRe: Rhetorical Question Pin
F-ES Sitecore5-Nov-18 0:56
professionalF-ES Sitecore5-Nov-18 0:56 
GeneralRe: Rhetorical Question Pin
CodeWraith5-Nov-18 0:58
CodeWraith5-Nov-18 0:58 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 1:20
Super Lloyd5-Nov-18 1:20 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 1:10
Super Lloyd5-Nov-18 1:10 
answer this question honestly, which one is more manual human editing friendly of the 2 formats below?

at any rate I much prefer to manually edit json (which is the whole point of a human friendly format), much less boiler plate code. no useless header, no useless "closing" tag.
as to do it by code.. it also much less troublesome to use than XML as far as I experienced it...
(as illustrated below by the difference between JSON and XML serialization code below)

C#
C#
public enum ItemType
{
    Image,
    Icon,
}
public class Item
{
    public ItemType Type { get; set; }
    public string Name { get; set; }
}
public class Document
{
    public List<Item> Items = new List<Item>();
}

class Program
{
    static void Main(string[] args)
    {
        var doc = new Document
        {
            Items =
            {
                new Item { Name = "foo", Type = ItemType.Icon, },
                new Item { Name = "bar", Type = ItemType.Icon, },
                new Item { Name = "snafu", Type = ItemType.Image, },
            },
        };

        // serialize to json, simple!
        var json = JsonConvert.SerializeObject(doc, Formatting.Indented);
        Console.WriteLine(json);

        // serialize to XML, kinda mouthful
        var xmlS = new XmlSerializer(typeof(Document));
        var sb = new StringBuilder();
        xmlS.Serialize(new StringWriter(sb), doc);
        var xml = sb.ToString();
        Console.WriteLine(xml);
    }

JSON
JavaScript
{
  "Items": [
    {
      "Type": 1,
      "Name": "foo"
    },
    {
      "Type": 1,
      "Name": "bar"
    },
    {
      "Type": 0,
      "Name": "snafu"
    }
  ]
}

XML
XML
<?xml version="1.0" encoding="utf-16"?>
<Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Items>
    <Item>
      <Type>Icon</Type>
      <Name>foo</Name>
    </Item>
    <Item>
      <Type>Icon</Type>
      <Name>bar</Name>
    </Item>
    <Item>
      <Type>Image</Type>
      <Name>snafu</Name>
    </Item>
  </Items>
</Document>
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 5-Nov-18 7:24am.

GeneralRe: Rhetorical Question Pin
CodeWraith5-Nov-18 1:18
CodeWraith5-Nov-18 1:18 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 1:22
Super Lloyd5-Nov-18 1:22 
GeneralRe: Rhetorical Question Pin
CodeWraith5-Nov-18 1:25
CodeWraith5-Nov-18 1:25 
GeneralRe: Rhetorical Question Pin
OriginalGriff5-Nov-18 1:21
mveOriginalGriff5-Nov-18 1:21 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 1:23
Super Lloyd5-Nov-18 1:23 
GeneralRe: Rhetorical Question Pin
F-ES Sitecore5-Nov-18 1:26
professionalF-ES Sitecore5-Nov-18 1:26 
GeneralRe: Rhetorical Question Pin
OriginalGriff5-Nov-18 1:30
mveOriginalGriff5-Nov-18 1:30 
GeneralRe: Rhetorical Question Pin
F-ES Sitecore5-Nov-18 2:19
professionalF-ES Sitecore5-Nov-18 2:19 
GeneralRe: Rhetorical Question Pin
Marc Clifton5-Nov-18 2:30
mvaMarc Clifton5-Nov-18 2:30 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 3:04
Super Lloyd5-Nov-18 3:04 
GeneralRe: Rhetorical Question Pin
#realJSOP5-Nov-18 2:36
professional#realJSOP5-Nov-18 2:36 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 3:02
Super Lloyd5-Nov-18 3:02 
GeneralRe: Rhetorical Question Pin
Eric Lynch5-Nov-18 3:05
Eric Lynch5-Nov-18 3:05 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 3:16
Super Lloyd5-Nov-18 3:16 
GeneralRe: Rhetorical Question Pin
RickZeeland5-Nov-18 4:03
mveRickZeeland5-Nov-18 4:03 
GeneralRe: Rhetorical Question Pin
Super Lloyd5-Nov-18 4:18
Super Lloyd5-Nov-18 4:18 
GeneralRe: Rhetorical Question Pin
megaadam5-Nov-18 5:01
professionalmegaadam5-Nov-18 5:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.