I recently came up against a wall when parsing JSON. You see, when working with the CloudFlare Client Interface API, i wanted to lookup the "threat rating" for a specific IP. The issue is that due to the design of the API, the format is something like this;
{
response: {
xxx.xxx.xxx.xxx: <value>,
calls_left: 299
},
result: "success",
msg: null
}
xxx.xxx.xxx.xxx
represents the field name i needed to retrieve data from. Immediately, you can probably see the issue i was facing; a dot character in a parse string is assumed to be a sublevel in the current path.
<value>
represents the actual rating of the IP. However, the format, and data type returned from it, varies. On IP's that aren't a threat, or don't have a threat rating, it returns false
as a boolean. On Search Engine crawlers, it returns "SE:<var>"
(where <var>
is a numerical value) as a string. On known threats, it returns "BAD:<var>"
(where <var>
is a numerical value). As such, i couldn't rely on a known data type being returned.
The main issue however, is that attempting to read the value from this field would obviously fail due to the dots within the field name.