JSON problem in App Development with Swift's project "Restaurant"

In iBook App Development with Swift's guided Project Restaurant

(chapter 5, page 837)

>> Build and run your app with the server running. You should see a list of the categories that you defined back in menu.json.


Problem :

  1. Nothing appears on the table view controller
  2. Enter http://localhost:8090/categories into the browser, but the server returns nothing.
    server response: { "categories" : [ ] }

Hi!

Have the same problem. Did you solved it ?

there's a mistake in the JSON – you've got a trailing comma after the last menu item. If you plug it into JSONLint you'll see the issue

Have you found a solution? I saw a fix on reddit but haven't tried yet. I fixed the JSON but that didn't seem to fix the problem.


https://www.reddit.com/r/swift/comments/6l80gj/json_problem_in_app_development_with_swifts/

Replying to my own issue in case someone encounters this:

(1) Addressing localhost will work from the local device, such as the xcode simulator, but not if you're using an external iPhone or iPad to run your code.

(2) JSON file has a trailing comma, needs to be deleted.

(3) Server file is broken, the reddit link above has the correct fix.

Please let me know if you find a better solution to this!

There is indeed an extra comma at the end of the JSON file, but the simple fix for localhost is to simply replace the substring in the baseURL with the IP of your Mac

I guess I found a solution:

Right-click on the OpenRestaurant icon - Choose Show package - Contents - Mac OS - Open Restaurant.

The server begins work for me.

I was stuck on it but your workaround solve my troubles. It works like a charm.

Thank you very much!

hi, it look like you go through it. i am stuck on this for days

so far i am delete the trailing comma on menu.json

save the OpenRestaurant.py file and run it on terminal.

my terminal show this after start the python file: [

Bottle v0.12.13 server starting up (using WSGIRefServer())...

Listening on http://localhost:8090/

]

But when i try to aceess to localhost:8090, it shown: [

Error: 404 Not Found

Sorry, the requested URL 'http://localhost:8090/' caused an error:

Not found: '/'
]


did i do anything wrong? any comment is greatly appreciated

i stuck at here and cant proceed further

hi, i am new to this. you said "simple fix for localhost is to simply replace the substring in the baseURL with the IP of your Mac"

may i ask how to do this? where to find the substring in the baseURL?

The app runs and pulls up the table views, but the categories are not displayed. I am getting this error message:


nw_socket_handle_socket_event [C1.1:2] Socket SO_ERROR [61: Connection refused]

nw_socket_handle_socket_event [C1.2:2] Socket SO_ERROR [61: Connection refused]

TIC TCP Conn Failed [1:0x283551bc0]: 1:61 Err(61)

Task <767BD871-B6DD-4CD8-87CA-84322344BF6B>.<1> HTTP load failed (error code: -1004 [1:61])

Task <767BD871-B6DD-4CD8-87CA-84322344BF6B>.<1> finished with error - code: -1004


I tried to run the file from the Reddit post, but it comes up with the same result. The server seems to be working, it doesn't look like it does exactly in the book, but going to the local server site shows: The restaurant is up and running! I think it may still blocking the HTTP even though I added the exception (and tried others) in info.plst.

I also tried the reddit python workaround and had no luck, still got the errors:

2020-06-20 03:01:58.688711-0700 Restaurant[9572:793454] [] nwsockethandlesocketevent [C1.1:2] Socket SOERROR [61: Connection refused]
2020-06-20 03:01:58.701424-0700 Restaurant[9572:793454] [] nw
sockethandlesocketevent [C1.2:2] Socket SOERROR [61: Connection refused]

and in my browser, only the "http://localhost:8090/categories" url works,not the "http://localhost:8090/menu" url.

I'd also be very interested to know how to use my Mac's IP address as a baseURL workaround.
In the file "MenuItem" in the CodingKeys enum, at the key "imageURL" the book makes you write "imageURL" but if you write "imageurl" (there is the underscore between image and url )the code works perfectly.
JSON problem in App Development with Swift's project "Restaurant"
 
 
Q