Parsing JSON using Json.net

后端 未结 5 966
既然无缘
既然无缘 2020-11-22 07:19

I\'m trying to parse some JSON using the JSon.Net library. The documentation seems a little sparse and I\'m confused as to how to accomplish what I need. Here is the forma

5条回答
  •  悲哀的现实
    2020-11-22 08:08

    Edit: Thanks Marc, read up on the struct vs class issue and you're right, thank you!

    I tend to use the following method for doing what you describe, using a static method of JSon.Net:

    MyObject deserializedObject = JsonConvert.DeserializeObject(json);
    

    Link: Serializing and Deserializing JSON with Json.NET

    For the Objects list, may I suggest using generic lists out made out of your own small class containing attributes and position class. You can use the Point struct in System.Drawing (System.Drawing.Point or System.Drawing.PointF for floating point numbers) for you X and Y.

    After object creation it's much easier to get the data you're after vs. the text parsing you're otherwise looking at.

提交回复
热议问题