Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not handle nest json objects #131

Open
kswain1 opened this issue Mar 8, 2019 · 0 comments
Open

Does not handle nest json objects #131

kswain1 opened this issue Mar 8, 2019 · 0 comments

Comments

@kswain1
Copy link

kswain1 commented Mar 8, 2019

Nested Json Package Below

The issue is that it's converting json dictionary objects into strings, and not it's proper value.

screen shot 2019-03-08 at 12 20 24 am

        "id": 16,
        "user_id": 6,
        "name": 4,
        "med_gastro": "{'left': {'mvc': 0, 'effeciency_score': 0, 'exhaustion': [0, 0, 0]}, 'right': {'mvc': 0, 'effeciency_score': 0, 'exhaustion': [0, 0, 0]}}",
        "lat_gastro": "{'left': {'mvc': 0, 'effeciency_score': 0, 'exhaustion': [0, 0, 0]}, 'right': {'mvc': 0, 'effeciency_score': 0, 'exhaustion': [0, 0, 0]}}",
        "tib_anterior": "{'left': {'mvc': '13816.0', 'effeciency_score': 20.804231942965192, 'exhaustion': {'maxEffeciency': 10.16597510373444, 'subMaxEffeciency': 3.2009484291641965, 'minEffeciency': 86.63307646710136}, 'effeciency': 20.804231942965192}, 'right': {'mvc': '13816.0', 'effeciency_score': 0, 'exhaustion': [0, 0, 0]}}",
        "peroneals": "{'left': {'mvc': 0, 'effeciency_score': 0, 'exhaustion': [0, 0, 0]}, 'right': {'mvc': 0, 'effeciency_score': 0, 'exhaustion': [0, 0, 0]}}"
    }

Coded Oject

import Foundation 
import ObjectMapper


class PlayerProfile : NSObject, NSCoding, Mappable{

	var id : Int?
	var latGastro : String?
	var medGastro : String?
	var name : Int?
	var peroneals : String?
	var tibAnterior : String?
	var userId : Int?


	class func newInstance(map: Map) -> Mappable?{
		return PlayerProfile()
	}
	required init?(map: Map){}
	private override init(){}

	func mapping(map: Map)
	{
		id <- map["id"]
		latGastro <- map["lat_gastro"]
		medGastro <- map["med_gastro"]
		name <- map["name"]
		peroneals <- map["peroneals"]
		tibAnterior <- map["tib_anterior"]
		userId <- map["user_id"]
		
	}

    /**
    * NSCoding required initializer.
    * Fills the data from the passed decoder
    */
    @objc required init(coder aDecoder: NSCoder)
	{
         id = aDecoder.decodeObject(forKey: "id") as? Int
         latGastro = aDecoder.decodeObject(forKey: "lat_gastro") as? String
         medGastro = aDecoder.decodeObject(forKey: "med_gastro") as? String
         name = aDecoder.decodeObject(forKey: "name") as? Int
         peroneals = aDecoder.decodeObject(forKey: "peroneals") as? String
         tibAnterior = aDecoder.decodeObject(forKey: "tib_anterior") as? String
         userId = aDecoder.decodeObject(forKey: "user_id") as? Int

	}

    /**
    * NSCoding required method.
    * Encodes mode properties into the decoder
    */
    @objc func encode(with aCoder: NSCoder)
	{
		if id != nil{
			aCoder.encode(id, forKey: "id")
		}
		if latGastro != nil{
			aCoder.encode(latGastro, forKey: "lat_gastro")
		}
		if medGastro != nil{
			aCoder.encode(medGastro, forKey: "med_gastro")
		}
		if name != nil{
			aCoder.encode(name, forKey: "name")
		}
		if peroneals != nil{
			aCoder.encode(peroneals, forKey: "peroneals")
		}
		if tibAnterior != nil{
			aCoder.encode(tibAnterior, forKey: "tib_anterior")
		}
		if userId != nil{
			aCoder.encode(userId, forKey: "user_id")
		}

	}

}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant