Skip to content
This repository has been archived by the owner on Oct 14, 2018. It is now read-only.

JSON parser breaks when parsing ids of locations within photo tags #32

Open
fer662 opened this issue Apr 20, 2018 · 3 comments
Open

JSON parser breaks when parsing ids of locations within photo tags #32

fer662 opened this issue Apr 20, 2018 · 3 comments

Comments

@fer662
Copy link

fer662 commented Apr 20, 2018

(lldb) po error
▿ DecodingError
  ▿ dataCorrupted : Context
    ▿ codingPath : 4 elements
      - 0 : CodingKeys(stringValue: "data", intValue: nil)
      ▿ 1 : _JSONKey(stringValue: "Index 4", intValue: 4)
        - stringValue : "Index 4"
        ▿ intValue : Optional<Int>
          - some : 4
      - 2 : CodingKeys(stringValue: "location", intValue: nil)
      - 3 : CodingKeys(stringValue: "id", intValue: nil)
    - debugDescription : "Parsed JSON number <531383683876521> does not fit in Int."
    - underlyingError : nil

Instagram sends strings for ids for pretty much everything, but it seems it sends ints for locations. Huge ints at that. They don't fit in 64 bits and the swift parser doesn't like that at all.

Edited/censored offending JSON. The data within the location node hasn't been altered:

{
	"pagination": {
		"next_max_id": "censored",
		"next_url": "censored"
	},
	"data": [{
		"id": "123123123_123123123",
		"user": {
			"id": "12345678",
			"full_name": "Censored",
			"profile_picture": "censored",
			"username": "censored"
		},
		"images": {
			"thumbnail": {
				"width": 150,
				"height": 150,
				"url": "censored"
			},
			"low_resolution": {
				"width": 320,
				"height": 320,
				"url": "censored"
			},
			"standard_resolution": {
				"width": 640,
				"height": 640,
				"url": "censored"
			}
		},
		"created_time": "1515524886",
		"caption": {
			"id": "12345678",
			"text": "censored",
			"created_time": "1515524886",
			"from": {
				"id": "1297516609",
				"full_name": "Censored",
				"profile_picture": "censored",
				"username": "censored"
			}
		},
		"user_has_liked": false,
		"likes": {
			"count": 17
		},
		"tags": [],
		"filter": "Normal",
		"comments": {
			"count": 0
		},
		"type": "image",
		"link": "censored",
		"location": {
			"latitude": -22.951586524616,
			"longitude": -43.210792243481,
			"name": "Cristo Redentor Rio de Janeiro",
			"id": 531383683876521
		},
		"attribution": null,
		"users_in_photo": []
	}],
	"meta": {
		"code": 200
	}
}
@fer662
Copy link
Author

fer662 commented Apr 20, 2018

It can be resolved by using InstagramLocation instead of InstagramLocation in 2 relevant places.

@AnderGoig
Copy link
Owner

Hi @fer662, I'm afraid I don't understand your solution. Could you give me more details?

@fer662
Copy link
Author

fer662 commented Apr 21, 2018

I meant to say
InstagramLocation<Int>
to
InstagramLocation<Decimal>
but i might have hit some kind of markup. There!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants