Grasshopper

algorithmic modeling for Rhino

Hey. For my research I am trying to deal with the APi of 4squares and Altergeo services,

one is Json based, another is Xml based.

Can somebody give me a hint how to begin doing that in grasshopper?

Should I just begin to write gets in C# component?

Views: 592

Reply to This

Replies to This Discussion

I'm assuming that you're more asking of a comparison between working with JSON vs XML as opposed to an evaluation of each API, since you don't actually indicate what you're trying to do.  For XML you've got quite a number of options natively within the .Net framework.  You've got the XmlReaders and XmlWriters, with support for pretty much everything you're going to run into with XML.  You've also got LINQ which you can use with XML, which is what I would recommend if you're going to go with the XML route.  LINQ is much easier, much more flexible to work with, and will in general have you writing significantly less code with LINQ to do the same thing than with the older xml namespaces.

 

As for JSON, I haven't worked with it, but I there isn't as much native support for it in the .Net framework, which means using an external library to help with parsing etc.  Under the context of a full blown GHA, this may not be an issue, but it might be more cumbersome to deal with an external library in a scripting component. One seemingly popular one to take a look at would be http://json.codeplex.com/.  As far as dealing with JSON without using an external library this post here looked pretty good.  I will say that both options rely on creating a dynamic object which is a .Net 4 ONLY type.  Without that it will not compile, so keep that in mind. There's also going to be a lot of casting if you want to deal with data as anything other than strings.

From my perspective, the biggest thing that matters is what you're trying to do and what each API can offer you to achieve those tasks.  There's no sense in using an API just cause it JSON, only to find out that it can't do what you need it to.  If you haven't worked with either technology, then both are going to take about the same effort (IMHO) to get up to speed on.  I will say that JSON is going to stretch things a little bit more than XML, but not so much that its not worth dealing with.

RSS

Translate

Search Grasshopper

Photos

  • Add Photos
  • View All

© 2014   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service