0

I am trying to do a simple weather widget for Android, that provides temperatures just for my country (Jordan). The website I am using for the weather records provides a JSON file with country regions data for many countries. The problem is that the file contains 2500+ objects, and it takes a really long time to be parsed. Thus, and as I actually need <100 of them (the regions of my country), I thought that I could optimize the file before passing it to the JSON parser, by taking off all of the records I don't need. I don't know if it's a good solution, but it was what I thought of. Anyway, my problem now is getting the right Regex.

This is the URL of the JSON file.

As you can see, every object has four items. The one I need to check for is "icon", which specifies the country of that region.

EXAMPLE:

{"value":"khalda","icon":"Jordan","label":"khalda","desc":"Amman & Madaba"},

What I could came up with so far is the pattern of the object I actually need. However, I need to get the ones I don't need to be able to delete them. Here is the pattern: \{[^\{]*Jordan*[^\}]*\}, (This has to be modified so it validates when "Jordan" does NOT exist, which I couldn't figure out.)

Any help/hint is highly appreciated. Thanks.

4

1 回答 1

0

与其匹配和删除您不需要的对象,不如匹配并提取您确实需要的单个(?)对象。它会更快。

(我同意 minitech 的评论。解析 JSON 文件不太可能成为真正的瓶颈。)

于 2012-05-26T02:42:07.533 回答