residuum / PuRestJson

PuREST JSON is a library for connecting Puredata (Pd) to HTTP services and encoding and decoding JSON data.
ix.residuum.org/pd/purest_json.html
Other
75 stars 9 forks source link

When using the Twitter example, routing the output to [json-decode] gives "Not a JSON object" error #32

Closed residuum closed 9 years ago

residuum commented 10 years ago

From @megrimm via email:

When example [GET /1.1/users/search.json?q=puredata{ is sent to [oauth] to get data from Twitter API, not all data is returned therefore giving a "Not a JSON object" using [json-decode]. Not sure the issue if its [oauth] or me...

here the pd console output:

data1: [\{"id":12096842,"id_str":"12096842","name":"IBM Netezza ","screen_name":"IBMNetezza","location":"Marlborough, MA","description":"IBM PureData for Analytics dramatically simplifies high-performance data analytics across the enterprise.","url":"http:\\/\\/t.co\\/xKEICQwg1L","entities":\{"url":\{"urls":[\{"url":"http:\\/\\/t.co\\/xKEICQwg1L","expanded_url":"http:\\/\\/www.ibmbigdatahub.com","display_url":"ibmbigdatahub.com","indices":[0,22]\}]\},"description":\{"urls":[]\}\},"protected":false,"followers_count":6643,"friends_count":3324,"listed_count":359,"created_at":"Fri Jan 11 03:04:23 +0000 2008","favourites_count":4,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":4651,"lang":"en","status":\{"created_at":"Tue Jun 25 16:52:33 +0000 2013","id":349570821603340288,"id_str":"349570821603340288","text":"@crystaanderson @TheSocialPitt - c'mon, I said \\"Go Blackhawks\\" surely that's enough #bruins","source":"\\u003ca

Not a JSON object

status1: bang
residuum commented 10 years ago

I suppose, this is Mac OS X. I have just tested it an my Debian, and though the output of oauth is truncated on Pd console or bash (if started with -stderr), I can connect the outlet to json-encode without problems.

Some thoughts on the error:

This search returns UTF-8 strings, including Asian characters.

Are you building using json-c 0.9? Then there is a crude fix for a unicode problem in the code (https://github.com/residuum/PuRestJson/blob/json-c-0.10/json-decode.c#L75). This code is wrong, because there are characters that are encoded to more than 4 hex characters.

Have you tried a search that only yields results from lower codepages? Something like "college%20football" comes to mind.

If that is the case, then someone needs to fix this crude fix to a correct one, or maybe an upgrade to a later version of json-c is required.

residuum commented 10 years ago

See also issue #5

megrimm commented 10 years ago

maybe an upgrade to a later version of json-c is required.

yeah the fink version is the problem. I just installed the latest json-c from github manually and all is fine compiling your lib... only that one change eliminating universal builds was necessary.

m

On Sun, Jan 19, 2014 at 4:00 PM, Thomas Mayer notifications@github.comwrote:

I suppose, this is Mac OS X. I have just tested it an my Debian, and though the output of oauth is truncated on Pd console or bash (if started with -stderr), I can connect the outlet to json-encode without problems.

Some thoughts on the error:

This search returns UTF-8 strings, including Asian characters.

Are you building using json-c 0.9? Then there is a crude fix for a unicode problem in the code ( https://github.com/residuum/PuRestJson/blob/json-c-0.10/json-decode.c#L75). This code is wrong, because there are characters that are encoded to more than 4 hex characters.

Have you tried a search that only yields results from lower codepages? Something like "college%20football" comes to mind.

If that is the case, then someone needs to fix this crude fix to a correct one, or maybe an upgrade to a later version of json-c is required.

This will not work with

— Reply to this email directly or view it on GitHubhttps://github.com/residuum/PuRestJson/issues/32#issuecomment-32719748 .


m.e.grimm | m.f.a | ed.m. megrimm@gmail.com


60-hz commented 9 years ago

Hi,

I have the same problem using windows and the last 1.1.0... any fixed release for this?

Here is what I have in my pd console:

raw_data: symbol \{"statuses":[\{"metadata":\{"iso_language_code":"en"\\,"result_type":"recent"\}\\,"created_at":"Tue Sep 23 17:32:04 +0000 2014"\\,"id":514467246308335616\\,"id_str":"514467246308335616"\\,"text":"@CNBC @Water Yeah because when it comes to #ClimateChange we all should look to #MattDamon for advice. Does he know how to fix a leak too?"\\,"source":"\\\\u003ca href=\\\\"http:\\\\/\\\\/twitter.com\\\\" rel=\\\\"nofollow\\\\"\\\\u003eTwitter Web Client\\\\u003c\\\\/a\\\\u003e"\\,"truncated":false\\,"in_reply_to_status_id":514466790332592129\\,"in_reply_to_status_id_str":"514466790332592129"\\,"in_reply_to_user_id":20402945\\,"in_reply_to_user_id_str":"20402945"\\,"in_reply_to_screen_name":"CNBC"\\,"user":\{"id":60201115\\,"id_str":"60201115"\\,"name":"Jason Billings"\\,"screen_name":"SingleDallasGuy"\\,"location":"Dallas\\, TX"\\,"description":"Just a guy in Dallas\\, TX taking each day as it comes. BTW\\, liberals piss me off!"\\,"url":null\\,"entities":\{"description":\{"urls":[]\}\}\\,"

raw_done: bang

decoded_data: list statuses [ \{ "metadata": \{ "iso_language_code": "en"\\, "result_type": "recent" \}\\, "created_at": "Tue Sep 23 17:32:04 +0000 2014"\\, "id": 514467246308335616\\, "id_str": "514467246308335616"\\, "text": "@CNBC @Water Yeah because when it comes to #ClimateChange we all should look to #MattDamon for advice. Does he know how to fix a leak too?"\\, "source": "<a href=\\\\"http:\\\\/\\\\/twitter.com\\\\" rel=\\\\"nofollow\\\\">Twitter Web Client<\\\\/a>"\\, "truncated": false\\, "in_reply_to_status_id": 514466790332592129\\, "in_reply_to_status_id_str": "514466790332592129"\\, "in_reply_to_user_id": 20402945\\, "in_reply_to_user_id_str": "20402945"\\, "in_reply_to_screen_name": "CNBC"\\, "user": \{ "id": 60201115\\, "id_str": "60201115"\\, "name": "Jason Billings"\\, "screen_name": "SingleDallasGuy"\\, "location": "Dallas\\, TX"\\, "description": "Just a guy in Dallas\\, TX taking each day as it comes. BTW\\, liberals piss me off!"\\, "url": null\\, "entities": \{ "description": \{ "urls": [ ]

decoded_data: list search_metadata \{ "completed_in": 0.039000\\, "max_id": 514467246308335616\\, "max_id_str": "514467246308335616"\\, "next_results": "?max_id=514467141685608450&q=%23climatechange&include_entities=1"\\, "query": "%23climatechange"\\, "refresh_url": "?since_id=514467246308335616&q=%23climatechange&include_entities=1"\\, "count": 15\\, "since_id": 0\\, "since_id_str": "0" \}

decoding_done: bang
residuum commented 9 years ago

@mrpropre: The example looks right, Puredata truncates the output, but the decoding of JSON is working correctly, even unicode portions (\u003ca).