[TIMOB-2388] Android: File.toString() fails
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | Trivial |
| Status | Closed |
| Resolution | Invalid |
| Resolution Date | 2011-04-15T03:18:26.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | n/a |
| Components | Android |
| Labels | android, defect, json, regression, tostring |
| Reporter | Robby |
| Assignee | Marshall Culpepper |
| Created | 2011-04-15T03:18:25.000+0000 |
| Updated | 2017-03-09T23:16:53.000+0000 |
Description
Fails when trying to read in JSON data from a file. E.g.
var slFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, slFilePath);
var slFileData = slFile.read();
Ti.API.info("JSON Data is: '" + slFileData.toString() + "'");
slCachedData = JSON.parse(slFileData.toString());
Where slFilePath is a valid path to a .json file with valid JSON data in it (this code works fine under iPhone with the same data). The above prints out "[INFO] [27,24101] JSON Data is: '[object TiBlob]'". Because the conversion to string does not work, I then get a JSON parse error:
[TRACE] E/KrollMethod( 450): (kroll$3) [4,24105] Exception calling kroll method parse, invocation: [callMethod JSON.parse ti.modules.titanium.json.JSONModuleBindingGen$2@451a19f0"json"=[object TiBlob]]
[TRACE] E/KrollMethod( 450): org.json.JSONException: Unterminated array at character 9 of [object TiBlob]
Makes sense as it's trying to parse that string as JSON, which it isn't.
Oops. Missed this post at:
http://developer.appcelerator.com/question/33111/object-tiblob-response-of-tostring"> http://developer.appcelerator.com/question/33111/object-tiblob-resp...
Wierd it's working on the iPhone though. This ticket can be closed.
Right.
Closing ticket as invalid.