0
votes

I'm working on a project developed for Android and using Titanium Studio 3.2.0 and Titanium SDK 3.2.0.GA.

I'm using Appcelerator Urban Airship module, I can connect with no problem, the main issue is that the payload I receive from Urban Airship looks like this:

{prop1={"key1":"val1","key2":"val2","key3":"val3"}}

Which is a string, not an object like you do in iOS.

The extra sent through curl like this:

curl -X POST -u "appkey:secret" \
   -H "Content-Type: application/json" \
   -H "Accept: application/vnd.urbanairship+json; version=3;" \
   --data '{"audience": {"alias": "foo"},"notification": {"alert":"hello","android": {"extra": {"prop1": "{\"key1\":\"val1\",\"key2\":\"val2\",\"key3\":\"val3\"}"}}},"device_types": ["android"]}' \
   https://go.urbanairship.com/api/push/

Is that a valid JSON object? I can't parse it with JSON.parse because of the = symbol, I could replace it but if I were to send an extra that contained several objects I was wondering if there was a way to quickly parse this kind of object.

Just to be clear, this is what I'm sending:

{"audience": {"alias": "foo"},"notification": {"alert":"hello","android": {"extra": {"prop1": "{\"key1\":\"val1\",\"key2\":\"val2\",\"key3\":\"val3\"}"}}},"device_types": ["android"]}

The bold is the payload I'm sending through Urban Airship. What I'm receiving on my app is the following:

{prop1={"key1":"val1","key2":"val2","key3":"val3"}}

If I were to send something like:

{"audience": {"alias": "foo"},"notification": {"alert":"hello","android": {"extra": {"prop1": "{\"key1\":\"val1\",\"key2\":\"val2\",\"key3\":\"val3\"}","prop2": "{\"key4\":\"val4\",\"key5\":\"val5\",\"key6\":\"val6\"}",...,"propN": "{\"keyX\":\"valX\",\"keyY\":\"valY\",\"keyZ\":\"valZ\"}"}}},"device_types": ["android"]}

I might receive a string that looks something like:

{prop1={"key1":"val1","key2":"val2","key3":"val3"},prop2={"{"key4":"val4","key5":"val5","key6":"val6"}",...,propN={"{"keyX":"valX","keyY":"valY","keyZ":"valZ"}"}

I want to know if there is a quick way to turn a string that looks like this into a JSON object. I know the string isn't a valid JSON object but if Urban Airship is sending something that looks like that then there should be a way to deal with an object that looks like this.

1
The first sample you give is not valid JSON because of the = sign as you sayrom99
yeah I thought so too, but Urban Airship is sending me that payload. As I mentioned in my question I want to know a fast way to turn that kind of object into a JSON object if we consider n number of properties in the extra sent in the curl.Uriel Arvizu
I guess a crude fix would be to quote the "prop1" text and replace the = with : (equals with colon) but not sure if that's what you're asking? I guess the service you are using has a bug if this is supposed to be a valid json string it's returning, sorry I don't know Urban Airship specificallyrom99
my question goes more on the what quick and efficient way can I turn this string into a JSON object. I'm only mentioning Urban Airship just if someone wanted to know where did I got this value, but I guess I should remove it from my tags since it's giving the wrong impressionUriel Arvizu

1 Answers

0
votes

Well the mystery was solved.

The data we received wasn't as odd as we thought at first. This is the usual structure for extras passed on Intents in Android. Since Titanium doesn't provide a way to parse this data, we had to do it manually by replacing the troublesome characters and structuring it like a normal JSON object.