I have an array of struct's that I need to write to a server side code, I can't seem to find any examples of adding a json object with multiple parent keys.
struct Photo {
var imageName = "", thumbFileURL = "", viewCount = 0, likeCount = 0
}
and then I have a couple of photo object that are declared like...
var photo1 = Photo()
photo1.imageName = "ImPhoto1"
photo1.thumbFileURL = "www.SO.com"
photo1.viewCount = 5
photo1.likeCount = 1
var photo2 = Photo()
photo1.imageName = "ImPhoto2"
photo1.thumbFileURL = "www.SO.com"
photo1.viewCount = 10
photo1.likeCount = 2
////// and then same for x amount of Photo() object
And then I have an array
myArray = [photo1,photo2,photo3, ...]
and then I need to write a json that looks something ike this:
myJson object = {
photo1: {
imageName: "ImPhoto1"
thumbFileURL = "www.SO.com"
viewCount: 5
likeCount: 1
},
photo2: {
imageName: "Imphoto2"
....
},
....
}
so my question is, how do I convert myarray -> myJson