Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2388] Android: File.toString() fails

GitHub Issuen/a
TypeBug
PriorityTrivial
StatusClosed
ResolutionInvalid
Resolution Date2011-04-15T03:18:26.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, defect, json, regression, tostring
ReporterRobby
AssigneeMarshall Culpepper
Created2011-04-15T03:18:25.000+0000
Updated2017-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.

Comments

  1. Robby 2011-04-15

    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.

  2. Bill Dawson 2011-04-15

    Right.

  3. Lee Morris 2017-03-09

    Closing ticket as invalid.

JSON Source