Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can keep quotes on strings from string resources

Tags:

java

android

xml

This is followup of a previous question (Android: Json string with spaces gives "Unterminated object at" exception)

When I get a string from a resource file it removes the " unless it is escaped (\") is there a way around this?

For example:

Java:

String jString = getResources().getString(R.string.event);

Json:

<resources>
    <string name="event">
        {"Array":[{"Name":"One two three"},{"Name":"Two"},{"Name":"Three"}]}
    </string>
</resources>

jString has a value of {Array:[{Name:One two three},{Name:Two},{Name:Three}]} and I want it to have the following value {"Array":[{"Name":"One two three"},{"Name":"Two"},{"Name":"Three"}]}.

like image 529
Andrew Boes Avatar asked May 19 '26 14:05

Andrew Boes


1 Answers

You can place the JSON document in res/raw/ and then use openRawResource(int) to get an InputStream from which you can read the JSON.

But depending on the data, I'd prefer saving it in a <string-array> or something like that.

like image 136
Julian Avatar answered May 22 '26 04:05

Julian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!