json: clean up script processing some

- use .empty() rather than .size() == 0
- use a const_iterator rather than BOOST_FOREACH
- validate iterators before creating a string from them
Merge pull request #2 from theuni/rawtx

As requested, a bit of cleanup in ParseScript()