added JSON encode for error codes, fixed <state> field.
Merge branch 'master' of https://github.com/andyF845/inv