-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
103 changed files
with
622 additions
and
468 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// | ||
// JSONParseManager.swift | ||
// Test | ||
// | ||
// Created by Yao on 2018/2/3. | ||
// Copyright © 2018年 Yao. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class JSONBuilder { | ||
|
||
static let shared: JSONBuilder = { | ||
let manager = JSONBuilder() | ||
return manager | ||
}() | ||
|
||
private var file: File! | ||
|
||
func buildWithJSONObject(_ obj: Any, file: File) -> (String, String?) { | ||
file.contents.removeAll() | ||
self.file = file | ||
var content : Content? | ||
let propertyKey = file.rootName.propertyName() | ||
|
||
switch obj { | ||
case let dic as [String: Any]: | ||
content = addDictionaryWithKeyName(propertyKey, dic: dic) | ||
case let arr as [Any]: | ||
_ = addArraryWithKeyName(propertyKey, valueArrary: arr) | ||
default: | ||
assertionFailure("parse object type error") | ||
} | ||
|
||
if let content = content { | ||
file.contents.insert(content, at: 0) | ||
} | ||
|
||
return file.toString() | ||
} | ||
|
||
|
||
private func addDictionaryWithKeyName(_ keyName: String, dic: [String: Any]) -> Content { | ||
let content = file.contentWithKeyName(keyName) | ||
|
||
dic.forEach { (item) in | ||
let keyName = item.key | ||
var property: Property? | ||
|
||
switch item.value { | ||
case _ as String: | ||
property = file.propertyWithKeyName(keyName, type: .String) | ||
case let num as NSNumber: | ||
property = file.propertyWithKeyName(keyName, type: num.valueType()) | ||
case let dic as [String: Any]: | ||
property = file.propertyWithKeyName(keyName, type: .Dictionary) | ||
let content = addDictionaryWithKeyName(keyName, dic: dic) | ||
file.contents.insert(content, at: 0) | ||
case let arr as [Any]: | ||
property = addArraryWithKeyName(keyName, valueArrary: arr) | ||
case _ as NSNull: | ||
property = file.propertyWithKeyName(keyName, type: .nil) | ||
default: | ||
assertionFailure("build JSON object type error") | ||
} | ||
|
||
if let propertyModel = property { | ||
content.properties.append(propertyModel) | ||
} | ||
} | ||
|
||
return content | ||
} | ||
|
||
private func addArraryWithKeyName(_ keyName: String, valueArrary: [Any]) -> Property? { | ||
var item = valueArrary.first | ||
if valueArrary.first is Dictionary<String, Any> { | ||
var temp = [String: Any]() | ||
valueArrary.forEach { temp.merge($0 as! [String: Any]) { $1 } } | ||
item = temp | ||
} | ||
|
||
if let item = item { | ||
var propertyModel: Property? | ||
switch item { | ||
case _ as String: | ||
propertyModel = file.propertyWithKeyName(keyName, type: .ArrayString) | ||
case let num as NSNumber: | ||
let type = PropertyType(rawValue: num.valueType().rawValue + 6)! | ||
propertyModel = file.propertyWithKeyName(keyName, type: type) | ||
case let dic as [String: Any]: | ||
propertyModel = file.propertyWithKeyName(keyName, type: .ArrayDictionary) | ||
let content = addDictionaryWithKeyName(keyName, dic: dic) | ||
file.contents.insert(content, at: 0) | ||
default: | ||
assertionFailure("build JSON object type error") | ||
break | ||
} | ||
|
||
return propertyModel | ||
}else { | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
JSONConverter/Vendor/Highlightr/Assets/Highlighter/LICENSE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Copyright (c) 2006, Ivan Sagalaev | ||
All rights reserved. | ||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above copyright | ||
notice, this list of conditions and the following disclaimer in the | ||
documentation and/or other materials provided with the distribution. | ||
* Neither the name of highlight.js nor the names of its contributors | ||
may be used to endorse or promote products derived from this software | ||
without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY | ||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY | ||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.