开发者

Using JSON data

开发者 https://www.devze.com 2022-12-21 17:50 出处:网络
I am trying to make a simple twitter client in C. I\'m new at this and not sure how to go about segregating meaningful stuff from the JSON string that I get from the API.

I am trying to make a simple twitter client in C. I'm new at this and not sure how to go about segregating meaningful stuff from the JSON string that I get from the API.

For example, if I get this as a 开发者_JS百科response from the API, how do I extract out the value of "text" into a string (char*)? I guess I can work with the string at low level, but wouldn't that become too tedious every time I need to get a value from the JSON string?


For JSON in general, json.org has a big list of parsers implemented in a ton of different languages.

For C:

  • JSON_checker
  • JSON parser
  • json-c
  • M's JSON parser
  • YAJL
  • cJSON
  • Jansson
  • jsmn


Why not just use one of the existing libraries for working w/ Twitter?

http://apiwiki.twitter.com/Libraries

As a more direct response to your question, I'd recommend not trying to do text parsing on your own, but instead have classes that mean something to your domain that you can then use the JSON serialization/deserialization logic that comes w/ the framework, e.g.

http://msdn.microsoft.com/en-us/library/bb412179.aspx

Hope that helps, Paul

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号