-1

Is it possible to create JSON files from text?

if so, is there a preferred way to do this on iOS?

Thanks

user773578
  • 1,161
  • 2
  • 13
  • 24
  • Your question is pretty vague. Can you describe in more detail what you're looking to do? What do these text files look like? – Michael Petrotta Oct 12 '11 at 00:44
  • I mean, can text fields be converted into JSON files? such as an excel file or UITextFields. How would one create a JSON file from these data layouts. like key/value pairs. – user773578 Oct 12 '11 at 01:00
  • How does one create a JSON file? Does it need to be coded? The reason I ask is because I need to create JSON files from the standard user, with no knowledge of code or anything close. – user773578 Oct 12 '11 at 01:04

2 Answers2

1

If you mean take some text that is in JSON format and make a JSON object you can get data from, yes. Look here:

https://stackoverflow.com/questions/286087/best-json-library-to-use-when-developing-an-iphone-application

Community
  • 1
  • 1
RyanG
  • 4,393
  • 2
  • 39
  • 64
1

There's nothing stopping you from persisting JSON objects to files but there's not really "JSON files" in the sense that there's XLS files.

JSON is a way of way of encoding objects into a textual format for lightweight data interchange.

http://en.wikipedia.org/wiki/JSON

You use JSON to turn objects into strings, typically transport over the wire between potentially disparate systems and then transform back to objects.

In iOS, there are may APIs to do this (which Ryan pointed out above):

https://stackoverflow.com/questions/286087/best-json-library-to-use-when-developing-an-iphone-application

If you wanted to save objects in JSON format to files, you can certainly do that:

Write a file on iOS

Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99
  • Thanks. I am a little confused about the fact that there arent JSON files. So, do objective C objects get converted to a JSON format, an app requests, receives and then converts it back to an object? how does one create JSON files without apps. such as, one can write out an XML file. – user773578 Oct 12 '11 at 01:33
  • The typical use of JSON is client server. Your client (phone) makes an http request to a server (http://server.com/employee/2). The server gets employee 2 from storage, turns it into an object server side (say C# for arguments sake), then returns it over the wire ... – bryanmac Oct 12 '11 at 01:36
  • ... when it goes over the wire, the server framework, turns it into a textual JSON format because many disparate clients on many disparate OSes have libraries to convert JSON to their object... – bryanmac Oct 12 '11 at 01:37
  • the phone recieves the JSON string from the http response and then uses one of the JSON APIs to turn it into an objective-c object. Now you can use that object how you use other objects in code. – bryanmac Oct 12 '11 at 01:38
  • It also goes the other way, create an objective-c object, use the API to turn it into a JSON string and then post or put that to a server over http. The server turns it into an object and operates on it. – bryanmac Oct 12 '11 at 01:39
  • ... So, it's typically a wire format. But, as I said ... nothing stops you from writing to a file - just not how it's typically used. iPhone has many other ways (plists, coredata etc...) to persist to disk. – bryanmac Oct 12 '11 at 01:40
  • thanks a lot. Re: your last comment, I had the server side of it in mind. Some way a user can create a JSON object, without knowing anything about code. e.g an excel file. but you cleared up exactly what I was wondering about. thanks again. – user773578 Oct 12 '11 at 01:59