x


Load JSON Resource as TextAsset

Hello, I'm trying to load a text file that contains JSON data as a TextAsset. This works fine if the extension of .txt is used,

For example myJson.txt works with:

TextAsset t = (TextAsset) Resources.Load("myJson", typeof(TextAsset));

However, when the extension is changed to .json, the resource will not load. How can we load the file as a TextAsset despite the .json extension? Is there a better way to load text from a file on runtime?

more ▼

asked Sep 11 '12 at 08:57 PM

absameen gravatar image

absameen
444 50 79 88

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

I think you are fine with the code, the problem is support:

http://docs.unity3d.com/Documentation/Components/class-TextAsset.html

Text Assets are a format for imported text files. When you drop a text file into your Project Folder, it will be converted to a Text Asset. The supported text formats are:

.txt .html .htm .xml .bytes

Something to ask be added as it is a more common "text" file format now.

more ▼

answered Sep 12 '12 at 07:26 AM

Joviex gravatar image

Joviex
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x71
x45
x26

asked: Sep 11 '12 at 08:57 PM

Seen: 1568 times

Last Updated: Sep 12 '12 at 07:26 AM