enjoysr / esjsonformat-xcode Goto Github PK
View Code? Open in Web Editor NEW将JSON格式化输出为模型的属性
License: MIT License
将JSON格式化输出为模型的属性
License: MIT License
Xcode 7.1 望及时更新
您好,首先谢谢贡献一个这么好的json生成模型的工具,让我又可以偷点懒了,O(∩_∩)O哈哈~。我说说使用过程中两点不是很爽的地方:1、模型属性中无对象属性的时候也会生成空@Class声明;2、模型中有数组属性最好可以默认给其名称加个s(大声告诉我不止我一个人有数组名称使用复数的强迫症,(^__^) 嘻嘻……)。以上是我使用后的两点建议,希望可以把这个好用的轮子造得越来越好。
原来我这种格式的是可以转化的
{
"buy_num" = 596;
discount = "10.0";
finalPrice = "9.9";
"is_collect" = n;
"is_today" = n;
numIid = 45711009510;
"pub_time" = "2015-09-01 17:00";
reservePrice = "9.9";
}
现在突然发现转化会报格式错误,报The data couldn’t be read because it isn’t in the correct format.。
不过你列举的那个json是可以转化的,
生成属性的顺序与输入的JSON key 顺序一一对应
JSON 源数据
{
"name": "王五",
"gender": "man",
"age": 15,
"height": "140cm",
}
现在输出的顺序是乱的(不是按照字母大小,也不是按照JSON key的顺序)
@property (nonatomic, copy) NSString *gender;
@property (nonatomic, assign) NSInteger age;
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *height;
xcode7.1 swift
json 数据
http://www.jisilu.cn/jisiludata/sfnew.php?___t=1433258531432
生成 数据:
var total: Int? = 0
var rows: [Rows]?
var page: Int? = 0
}
class Rows: NSObject {
var id: String?
var cell: Cell?
}
class Cell: NSObject {
var upper_recalc_price: String?
var a_amount_increase_rt: String?
var fund_company_nm: String?
var recalc_to: String?
var calc_info: String?
var base_fund_nm: String?
var base_est_dis_rt: String?
var coupon_descr_s: String?
var min_apply_amount: String?
var manage_fee: String?
var fully: String?
var coupon: String?
var apply_fee: String?
var fund_descr: String?
var mtrade: String?
var coupon_descr: String?
var last_chg_dt: String?
var base_est_dis_rt_tip: String?
var issue_dt: String?
var fundA_nm: String?
var active_fl: String?
var fundA_id: String?
var coupon_next: String?
var fundB_nm: String?
var apply_fee_tip: String?
var redeem_fee: String?
var mujiprice: String?
var fundB_id: String?
var price: String?
var maturity_dt: String?
var redeem_fee_tip: String?
var lower_recalc_price: String?
var mujidate: String?
var left_year: String?
var index_nm: String?
var abrate: String?
var a_amount: String?
var a_ratio: String?
var coupon_next2: String?
var index_id: String?
var asset_ratio: String?
var base_lower_recalc_rt: String?
var base_fund_id: String?
var lower_recalc_comment: String?
var notes: String?
var next_recalc_dt: String?
var market: String?
var b_ratio: String?
var b_gangan: String?
var status_cd: String?
{
createName = "";
createTime = "";
hotSearchId = 10;
hotSearchName = "\U5546\U5bb65";
hotSearchType = 0;
memo = "";
updateName = "";
updateTime = "";
}
您好,目前所用的格式是这样,一直提示格式错误,能否增加格式编辑功能?
it would be a great feature to allow Swift code generation (i'd love to help)
下面是我用的JSON
[
{
"id": 1,
"uid": 1,
"scene_id": 1,
"single_scene_img_id": "",
"background": "",
"link": "",
"effect": "",
"app_id": 0,
"app_attr_name": "",
"app_param": "",
"is_del": "N",
"create_at": 1437559251,
"elements": [
{
"id": 3872,
"scene_id": 195,
"scene_detail_id": 979,
"content": "",
"type": "img",
"properties": "",
"create_at": 1437618000
}
],
"page": 2,
"num": 1
}
]
额 外层是数组的时候会有问题。。。 我把数据手动解了。
1.在RootClass里,如果你命名错了一个子类,那么在.h 跟.m文件里清掉所有代码,再重新解析并生成代码时,之前删掉的代码又会出现了,除非删掉RootClass,再重建一个.
2.命名错误,只能一路错到底,不能中断...
Swift
麻烦增加初始化方法, 谢谢. 只生成属性仅完成了一半的工作. model类应该增加一个传入键值对初始化方法,或者传入数组初始化.
XCode7 中objective-C也可以有泛型了
{
PicUrl : /upFile/house/loupan/20151015/20151015235322_7825.jpg,
TJHX : 2室90平,3室117平,
MapX : ,
fyhao : 4,
}
有一个 空值,
键和值 中的字符串都没有双引号 不能识别
发现和Vim一起使用的时候,生成Model会失败
这是我从新浪API 接口中返回的 JSON 数据中的一段:
"statuses": [
{
"created_at": "Tue May 31 17:46:55 +0800 2011",
"id": 11488058246,
"text": "求关注。",
"source": "新浪微博",
问题出在 source 这里,source 对应的 value 中包含了多个引号 “” ,应该是不能正确识别了,一直报错误:The data couldn’t be read because it isn’t in the correct format. 去掉这行之后就可以正确转换,希望作者有时间的话可以改进一下这个小 bug,用着真的挺方便的,感谢。
报错为,The operation couldn't be completed (Current state is not edit! error 0.)
试试半夜睡不着
Xcode 6.2使用后直接闪退。多次。数据量也不是很多。
看看MJExtension如何做,json中有关键字转完后生成文件后,你最好提示一下开发者,.m有文件也要提示开发者,比如来个注释或者#waring ...
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Application Specific Information:
Sending enterButtonClick: to <ESInputJsonController: 0x7fc23e149c90> from <NSButton: 0x7fc23f30c1b0>
ProductBuildVersion: 6D570
UNCAUGHT EXCEPTION (NSGenericException): *** Collection <__NSDictionaryM: 0x7fc23e93dbb0> was mutated while being enumerated.
UserInfo: (null)
Hints:
0: Sending enterButtonClick: to <ESInputJsonController: 0x7fc23e149c90> from <NSButton: 0x7fc23f30c1b0>
Backtrace:
0 0x00007fff8e0b6024 __exceptionPreprocess (in CoreFoundation)
1 0x000000010974f184 DVTFailureHintExceptionPreprocessor (in DVTFoundation)
2 0x00007fff9335d76e objc_exception_throw (in libobjc.A.dylib)
3 0x00007fff8e0b58d5 __NSFastEnumerationMutationHandler (in CoreFoundation)
4 0x0000000119056f8a -[ESInputJsonController dealNameWithDictionary:] at /Users/Jomy/Desktop/ESJsonFormat-Xcode-master/ESJsonFormat/Controller/ESInputJsonController.m:100 (in ESJsonFormat)
5 0x0000000119056a45 -[ESInputJsonController enterButtonClick:] at /Users/Jomy/Desktop/ESJsonFormat-Xcode-master/ESJsonFormat/Controller/ESInputJsonController.m:65 (in ESJsonFormat)
6 0x00007fff97d8acd7 _os_activity_initiate (in libsystem_trace.dylib)
7 0x00007fff8b1b9fb1 -[NSApplication sendAction:to:from:](in AppKit)
8 0x0000000109cd280d __37-[DVTApplication sendAction:to:from:]_block_invoke (in DVTKit)
9 0x000000010974eec2 DVTInvokeWithFailureHint (in DVTFoundation)
10 0x0000000109b9b0ce -[DVTApplication sendAction:to:from:](in DVTKit)
11 0x00007fff8b1cfa46 -[NSControl sendAction:to:](in AppKit)
12 0x00007fff8b1cf962 __26-[NSCell _sendActionFrom:]_block_invoke (in AppKit)
13 0x00007fff97d8acd7 _os_activity_initiate (in libsystem_trace.dylib)
14 0x00007fff8b1cf8bf -[NSCell _sendActionFrom:](in AppKit)
15 0x00007fff97d8acd7 _os_activity_initiate (in libsystem_trace.dylib)
16 0x00007fff8b1cddb3 -[NSCell trackMouse:inRect:ofView:untilMouseUp:](in AppKit)
17 0x00007fff8b22645f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:](in AppKit)
18 0x00007fff8b1cc466 -[NSControl mouseDown:](in AppKit)
19 0x00007fff8b7362fc -[NSWindow _reallySendEvent:isDelayedEvent:](in AppKit)
20 0x00007fff8b0c5d76 -[NSWindow sendEvent:](in AppKit)
21 0x00007fff8b0c2312 -[NSApplication sendEvent:](in AppKit)
22 0x000000010a7cb494 -[IDEApplication sendEvent:](in IDEKit)
23 0x00007fff8afebc68 -[NSApplication run](in AppKit)
24 0x00007fff8af68354 NSApplicationMain (in AppKit)
25 0x00007fff95b845c9 start (in libdyld.dylib)
如题,例如默认用相同的 key 生成关键字
生成模型后如果能再每个属性的上面生成默认的注释
{
"ret_code" : 200,
"err" : "",
"data" : [
[
0,
1439864742,
{
"posts/lists" : [
{
"ret_code" : 200,
"err" : "",
"data" : [
{
"u_nick" : "管理员",
"p_id" : 1,
"content" : "87为人民大会堂特制,习水大曲一瓶。酒满品好,900元。",
"u_face_url" : "",
"like_count" : 3,
"title" : "87为人民大会堂特制,习水大曲一瓶",
"publish_time" : "2015-08-08",
"u_id" : 5,
"comment_count" : 2,
"cover" : "",
"read_count" : 0
} ]
}
]
}
]
]
}
我用ESJsonFormat只能解析到posts/lists,之后的数组是nil....希望早点解决 谢谢
这是什么原因 Xcode 6.3
看看MJExtension如何做,json中有关键字转完后生成文件后,你最好提示一下开发者,.m有文件也要提示开发者,比如来个注释或者#waring ...
{
"name": "123",
"description": "122",
"renders": [
"11",
"11"
],
"parses": [
"22",
"33",
"44"
]
}
以便在 DCKeyValueObjectMapping 中不会因为 “Null" 而产生 crash
还有Bool
RT
我们后端返回的这种数据,没法用啊。
{
data = {
album = (
);
"attr_num" = 10;
"dynamic_num" = 20;
"fans_num" = 9;
"friends_num" = 5;
hobby = "";
integral = 102;
level = 0;
nickname = "\U8f7b\U8214\U6307\U5c16";
rmb = 96936;
signature = "";
};
msg = success;
result = 1;
}
当数据里面的id这个key的时候,能否自动转换成大写的ID
{
cluId: 2,
effectiveLastTime: 1438223201000,
id: 3,
money: 100,
sequence: "desc",
showTime: "2015-07-02 10:26",
status: 0,
time: 1435804008000,
title: "优惠券"
}
似乎和插件有关
UNCAUGHT EXCEPTION (NSInvalidArgumentException): -[NSNull absoluteString]: unrecognized selector sent to instance 0x7fff725b2210
UserInfo: (null)
Hints: None
Backtrace:
0 0x00007fff86baa024 __exceptionPreprocess (in CoreFoundation)
1 0x000000010c5fbbb4 DVTFailureHintExceptionPreprocessor (in DVTFoundation)
2 0x00007fff83e7276e objc_exception_throw (in libobjc.A.dylib)
3 0x00007fff86bad0ad -[NSObject(NSObject) doesNotRecognizeSelector:] (in CoreFoundation)
4 0x00007fff86af2e24 ___forwarding___ (in CoreFoundation)
5 0x00007fff86af2998 _CF_forwarding_prep_0 (in CoreFoundation)
6 0x0000000117b9f1e5 -[ESJsonFormat notificationLog:] at /Users/xxx/Library/Application Support/Alcatraz/Plug-ins/ESJsonFormat/ESJsonFormat/ESJsonFormat.m:47 (in ESJsonFormat)
7 0x00007fff86b6645c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ (in CoreFoundation)
8 0x00007fff86a56634 _CFXNotificationPost (in CoreFoundation)
9 0x00007fff8c3a99d1 -[NSNotificationCenter postNotificationName:object:userInfo:] (in Foundation)
10 0x000000010c5d7918 -[NSNotificationCenter(DVTNSNotificationCenterAdditions) _dvt_postNotificationName:object:userInfo:] (in DVTFoundation)
11 0x000000010d78a8c7 -[IDEEditorDocument _sendOutDocumentUpdateLocation] (in IDEKit)
12 0x00007fff8c3ed41b __NSFireDelayedPerform (in Foundation)
13 0x00007fff86afd2e4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ (in CoreFoundation)
14 0x00007fff86afcf73 __CFRunLoopDoTimer (in CoreFoundation)
15 0x00007fff86b7053d __CFRunLoopDoTimers (in CoreFoundation)
16 0x00007fff86ab8608 __CFRunLoopRun (in CoreFoundation)
17 0x00007fff86ab7bd8 CFRunLoopRunSpecific (in CoreFoundation)
18 0x00007fff86ec756f RunCurrentEventLoopInMode (in HIToolbox)
19 0x00007fff86ec72ea ReceiveNextEventCommon (in HIToolbox)
20 0x00007fff86ec712b _BlockUntilNextEventMatchingListInModeWithFilter (in HIToolbox)
21 0x00007fff8fc079bb _DPSNextEvent (in AppKit)
22 0x00007fff8fc06f68 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in AppKit)
23 0x000000010cb81aaa -[DVTApplication nextEventMatchingMask:untilDate:inMode:dequeue:] (in DVTKit)
24 0x00007fff8fbfcbf3 -[NSApplication run] (in AppKit)
25 0x00007fff8fb79354 NSApplicationMain (in AppKit)
26 0x00007fff898d05c9 start (in libdyld.dylib)
27 0x0000000000000001
no GUI pops up after clicking settings and input json
@Property (nonatomic, copy) NSString *order_status_id;
@Property (nonatomic, copy) NSString *order_type_id;
@Property (nonatomic, copy) NSString *interest_time;
@Property (nonatomic, assign) NSInteger ID;
@Property (nonatomic, copy) NSString *agreement_uuid;
+(NSDictionary *)replacedKeyFromPropertyName
{
return @{@"id":@"id"};
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.