New Posts  All Forums:Forum Nav:

JSON Hosting in php

post #1 of 3
Thread Starter 
So, I was recently hired to write an iPhone app for a small business,
This application will need to get Strings from a server (in a database but thats another story) and parse them as text.
As in something like this
Code:
[{"Name":"John","Value":22,"Colour":"brown","City":"Auckland"}

What I can not get my head around is how I can host a JSON file in my local webserver (using MAMP)
like this one http://api.kivaws.org/v1/loans/search.json?status=fundraising
Because I can parse from that^ Webservice but not from my own webservice
From what I have read, I need some sort of JSON wrapper, but I am yet to find information on that

Oh and yes I can access my local webservice from the Browser in the iPhone.


All of the tutorials seem to have different JSON formatting


SO:

How do I host a .JSON file like http://api.kivaws.org/v1/loans/search.json?status=fundraising
Edited by jakethesnake438 - 2/4/13 at 2:19pm
4K ITX
(14 items)
 
Work machine
(9 items)
 
 
CPUMotherboardGraphicsRAM
3770k [4.4GHZ] Asrock Z77E-ITX EVGA 980Ti SC ACX [1455/3801] 12GB 1600MHz 
Hard DriveHard DriveCoolingOS
256GB Samsung 128Gb Sandisk SSD Seidon 120V Windows 10 
MonitorKeyboardCaseMouse
2 x Dell P2715Q 4K Apple Kbd Silverstone SG13B Logitech G602 
Mouse PadAudio
Steelseries QCK Senheiser HD449 
CPUMotherboardGraphicsRAM
i7 4870HQ @2.5GHz Macbook Pro 2015 Radeon R9 M370X 2GB 16GB DDR3 1600MHz 
Hard DriveOSMonitorKeyboard
512GB PCI-E X4 SSD SM0512G  macOS 2x Dell U2715H Apple wired 
Mouse
Logitech G402 
  hide details  
Reply
4K ITX
(14 items)
 
Work machine
(9 items)
 
 
CPUMotherboardGraphicsRAM
3770k [4.4GHZ] Asrock Z77E-ITX EVGA 980Ti SC ACX [1455/3801] 12GB 1600MHz 
Hard DriveHard DriveCoolingOS
256GB Samsung 128Gb Sandisk SSD Seidon 120V Windows 10 
MonitorKeyboardCaseMouse
2 x Dell P2715Q 4K Apple Kbd Silverstone SG13B Logitech G602 
Mouse PadAudio
Steelseries QCK Senheiser HD449 
CPUMotherboardGraphicsRAM
i7 4870HQ @2.5GHz Macbook Pro 2015 Radeon R9 M370X 2GB 16GB DDR3 1600MHz 
Hard DriveOSMonitorKeyboard
512GB PCI-E X4 SSD SM0512G  macOS 2x Dell U2715H Apple wired 
Mouse
Logitech G402 
  hide details  
Reply
post #2 of 3
Thread Starter 
Talking to myself BUT, I found that to create a JSON file you change the extension to .json
I feel silly.

All is well
4K ITX
(14 items)
 
Work machine
(9 items)
 
 
CPUMotherboardGraphicsRAM
3770k [4.4GHZ] Asrock Z77E-ITX EVGA 980Ti SC ACX [1455/3801] 12GB 1600MHz 
Hard DriveHard DriveCoolingOS
256GB Samsung 128Gb Sandisk SSD Seidon 120V Windows 10 
MonitorKeyboardCaseMouse
2 x Dell P2715Q 4K Apple Kbd Silverstone SG13B Logitech G602 
Mouse PadAudio
Steelseries QCK Senheiser HD449 
CPUMotherboardGraphicsRAM
i7 4870HQ @2.5GHz Macbook Pro 2015 Radeon R9 M370X 2GB 16GB DDR3 1600MHz 
Hard DriveOSMonitorKeyboard
512GB PCI-E X4 SSD SM0512G  macOS 2x Dell U2715H Apple wired 
Mouse
Logitech G402 
  hide details  
Reply
4K ITX
(14 items)
 
Work machine
(9 items)
 
 
CPUMotherboardGraphicsRAM
3770k [4.4GHZ] Asrock Z77E-ITX EVGA 980Ti SC ACX [1455/3801] 12GB 1600MHz 
Hard DriveHard DriveCoolingOS
256GB Samsung 128Gb Sandisk SSD Seidon 120V Windows 10 
MonitorKeyboardCaseMouse
2 x Dell P2715Q 4K Apple Kbd Silverstone SG13B Logitech G602 
Mouse PadAudio
Steelseries QCK Senheiser HD449 
CPUMotherboardGraphicsRAM
i7 4870HQ @2.5GHz Macbook Pro 2015 Radeon R9 M370X 2GB 16GB DDR3 1600MHz 
Hard DriveOSMonitorKeyboard
512GB PCI-E X4 SSD SM0512G  macOS 2x Dell U2715H Apple wired 
Mouse
Logitech G402 
  hide details  
Reply
post #3 of 3
JSON files are just text files. You don't need to have a .json extension (you don't need any extension), but you will want to make sure that the web server specifies the Content-Type header to be "application/json". That way the browser will know how to handle it without you having to explicitly parse it as JSON.

As far as formatting goes it just depends what sort of data you want to return. If you want to store a list of values then you'll have an array (which uses square brackets). If you want to store a bunch of key/value pairs then you'll make it a JSON Object (which uses braces). You can combine both and nest them as deep as you want as well, eg. you could have several key/value pairs where one value is an array or another Object, which in turn could store more arrays or Objects (or integers, strings, etc). It's not really that important how you format it as long as it is valid JSON. There are plenty of JSON validators you can use to check that your output is correct. Of course pretty much every browser will spit in your face if you try to get it to handle invalid JSON as well.
Edited by randomizer - 2/6/13 at 2:22am
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E Gigabyte GTX 970 (GV-N970IX-4GD) 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 920 D0 MSI X58 Pro-E Gigabyte GTX 970 (GV-N970IX-4GD) 3x2GB G.Skill DDR3-1333 9-9-9-24 
Hard DriveHard DriveOptical DriveOS
840 Pro Caviar Black LG BD-ROM Windows 8.1 Pro x64 
MonitorMonitorKeyboardPower
Dell U2713HM Dell U2311H Turbo-Trak (Google it :D) Corsair HX-520 
CaseMouseMouse PadAudio
CM690 Mionix Avior 7000 Everglide Titan AKG K 242 HD 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding