JSONSerialization

YesCoach·2021년 7월 6일
0

JSONSerialization 공식문서

JSON과 동등한 Foundation 객체 간에 변환되는 객체

Declaration

class JSONSerialization: NSObject

Overview

JSONSerialization 클래스를 사용하여 JSON을 Foundation 객체로 변환하고 Foundation 객체를 JSON으로 변환할 수 있습니다.

JSON으로 변환할 수 있는 Foundation 객체에는 다음 속성이 있어야 합니다.

  • 최상위 객체는 NSArray 또는 NSDictionary입니다.
  • 모든 객체는 NSString, NSNumber, NSArray, NSDictionary 또는 NSNull의 인스턴스입니다.
  • 모든 딕셔너리 키는 NSSring의 인스턴스입니다.
  • 숫자는 NaN이나 무한대가 아니다.

다른 규칙이 적용될 수 있습니다. isValidJSONObject(_:)를 호출하거나 변환을 시도하는 것이 지정된 객체를 JSON 데이터로 변환할 수 있는지 여부를 확인하는 결정적인 방법입니다.

Thread Safety
On iOS 7 and later and macOS 10.9 and later JSONSerialization is thread safe.

Topics

Creating a JSON Object

  • class func jsonObject(with: Data, options: JSONSerialization.ReadingOptions) -> Any
    지정된 JSON 데이터에서 Foundation 개체를 반환합니다.
  • class func jsonObject(with: InputStream, options: JSONSerialization.ReadingOptions) -> Any
    지정된 스트림의 JSON 데이터에서 Foundation 개체를 반환합니다.

Creating JSON Data

class func data(withJSONObject: Any, options: JSONSerialization.WritingOptions) -> Data
Foundation 객체에서 JSON 데이터를 반환합니다.
class func writeJSONObject(Any, to: OutputStream, options: JSONSerialization.WritingOptions, error: NSErrorPointer) -> Int
지정된 JSON 객체를 스트림에 씁니다.
class func isValidJSONObject(Any) -> Bool
지정된 객체를 JSON 데이터로 변환할 수 있는지 여부를 나타내는 부울 값을 반환합니다.

Constants

struct JSONSerialization.ReadingOptions
JSON 데이터에서 Foundation 개체를 생성할 때 사용되는 옵션—jsonObject(옵션: 포함) 및 jsonObject(옵션: 포함)를 참조
struct JSONSerialization.WritingOptions
데이터 쓰기 옵션.

Inherits From

  • NSObject

See Also

JSON

  • { } Using JSON with Custom Types
    Swift의 JSON 지원을 사용하여 JSON 데이터의 구조에 관계없이 인코딩 및 디코딩할 수 있습니다.
  • class JSONEncoder
    데이터 유형의 인스턴스를 JSON 객체로 인코딩하는 객체입니다.
  • class JSONDecoder
    JSON 개체에서 데이터 유형의 인스턴스를 디코딩하는 객체
profile
iOS dev / Japanese with Computer Science

0개의 댓글