开发者

Parsing JSON in C? [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicates:

Does Windows have a JSON API that can be called from C?

Using JSON data

How to parse JSON to an object in C. I know it's easy for scripting languages like Ruby, PHP,开发者_JAVA百科 etc. They just need to call a simple function (eg. json_decode($str) in PHP ) and the str will be parsed to a dynamic object or associative array.

What about doing this in C? Are there any examples?


json-glib seems to be the best option if you're on Linux. There's a plethora of other choices if that doesn't work for you.


The best way to handle JSON in C depends a lot on whether you want to process abstract, fully general JSON with arbitrary keys, types, and hierarchy, or whether you're working with data that has a fixed set of allowed fields, types for those fields, and instances in which case nesting is valid. In the latter case, you would do well to make C structures corresponding to the JSON you want to accept, and specialized code to fill those structures. For fully general JSON, you want a general-purpose library (with all the bloat that entails, as well as the performance cost of looking up values by a string key each time you want to access them rather than with a simple . or -> operator).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜