//
//  JSONUtils.swift
//  Chat Application 1
//
//  Created by Avaya on 23/09/2016.
//  Copyright © 2016 Avaya. All rights reserved.
//

import Foundation
import SwiftyJSON


public class JSONUtils{
    
    public func convertObjectIntoJSON(object: AnyObject) -> String{
        
        
        return ""
    }
    
    
    public func parseJSONFromFile(){
        
        //get json file
        let path: String = Bundle.main.path(forResource: "ping", ofType: "json")!
        
        let myData = NSData(contentsOfFile: path) as NSData?
        
        
        //convert file with swiftyJSON
        do {
            let convert = try JSON(data: myData! as Data, options: JSONSerialization.ReadingOptions.mutableContainers)

        
        let apiVersion = convert["apiVersion"]
        let type = convert["type"]
        let body = convert["body"]
        
        
        print("api Version \(apiVersion)")
        print("type \(type)")
        print("body \(body)")
        
        print("*****")
        
        
        let nested = body["method"]
        print("Nested value method 1 \(nested)")
        let nested1 = convert["body","method"]
        print("Nested Value method 2 \(nested1)")
        let nested2 = convert["body"]["method"]
        print("Nested Value method 3 \(nested2)")
            
        } catch {
            
        }
        
    }
    
    
}
