从Jackson 2.2的ObjectMapper中打印JSON(Pretty printing JSON from Jackson 2.2's ObjectMapper)
现在我有一个
org.fasterxml.jackson.databind.ObjectMapper
的实例,并希望得到一个具有漂亮JSON的String
。 我的Google搜索的所有结果都提出了Jackson 1.x的这种做法,我似乎找不到适当的,不被弃用的方法,使用2.2。 即使我不认为代码对于这个问题是绝对必要的,这里是我现在所说的:ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); System.out.println("\n\n----------REQUEST-----------"); StringWriter sw = new StringWriter(); mapper.writeValue(sw, jsonObject); // Want pretty version of sw.toString() here
Right now I have an instance of
org.fasterxml.jackson.databind.ObjectMapper
and would like to get aString
with pretty JSON. All of the results of my Google searches have come up with Jackson 1.x ways of doing this and I can't seem to find the proper, non-deprecated way of doing this with 2.2. Even though I don't believe that code is absolutely necessary for this question, here's what I have right now:ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); System.out.println("\n\n----------REQUEST-----------"); StringWriter sw = new StringWriter(); mapper.writeValue(sw, jsonObject); // Want pretty version of sw.toString() here
原文:https://stackoverflow.com/questions/17617370
最满意答案
[self setDelegate:self.superview];
这就是问题。
您应该将
ViewController
设置为委托的引用。例如,在
ViewController
分配ImageDemoGridViewCell
后,请按如下方式设置委托。ImageDemoGridViewCell *cell = [[ImageDemoGridViewCell alloc] initWith..]; cell.delegate = self;
然后将单元格作为子视图添加到
ViewController
的视图中。[self setDelegate:self.superview];
This is the problem.
You should set the
ViewController
as the reference for the delegate.For example, after you have allocated the
ImageDemoGridViewCell
inViewController
, set the delegate as follows.ImageDemoGridViewCell *cell = [[ImageDemoGridViewCell alloc] initWith..]; cell.delegate = self;
Then add the cell as subview to the
ViewController
s view.
相关问答
更多-
[self setDelegate:self.superview]; 这就是问题。 您应该将ViewController设置为委托的引用。 例如,在ViewController分配ImageDemoGridViewCell后,请按如下方式设置委托。 ImageDemoGridViewCell *cell = [[ImageDemoGridViewCell alloc] initWith..]; cell.delegate = self; 然后将单元格作为子视图添加到ViewController的视图中。 ...
-
这一行: [self.currentTextfield replaceRange:self.currentTextfield.selectedTextRange withText:entryString]; 不会导致对textField:shouldChangeCharactersInRange:replacementString:的调用textField:shouldChangeCharactersInRange:replacementString: 这是你所期待的吗? 由于您明确地更改了文本字段的文本 ...
-
您需要在RatingViewController.m的viewDidLoad方法中设置委托。 委托不是按原样设置的,因为当调用initWithFrame:andRating: , _ratingViewController为nil 。 另外,在UIView引用UIViewController是不好的做法。 它不仅会创建一个保留周期,而且会忽略使用委托的一半原因:添加任何符合DelegateForSlider对象可以设置为StarRatingView的delegate属性的灵活性。 有关委托检查的更多信息,请 ...
-
我怀疑问题在于你在VARendererViewController中初始化一个VASettingsView的新实例,而不是获得一个指向屏幕上的指针的指针。 由于您没有展示如何在屏幕上获得VASettingsView,或者您如何创建其视图,这只是一种猜测。 编辑后: 代替, VASettingsView *settingsView = [[VASettingsView alloc] init]; settingsView.delegate = self; 尝试这个, VASettingsView *sett ...
-
我想你错过了一些东西。 你的声明是完美的,但你的电话是不正确的。 它应该如下... 视图控制器 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. LoginService *ls = [[LoginService alloc]init]; ls.delegate=self; [ls log ...
-
好吧,我终于找到了问题。 在我的xib文件中,我将UIView类设置为自定义控件类名称,而不是设置文件所有者。 一旦我将xib中的第一个UIView改回到标准的UIView,然后将文件所有者设置为我的自定义类,那么所有的东西都是正确的! - 感谢所有试图帮助的人! Ok so I finally found the problem. In my xib file I had set the UIView class to my custom controls class name instead of se ...
-
SXMainController *mainController = [[SXMainController alloc] init]; self.delegate = mainController; [self.delegate detectAlgorihtm:self outputBufferValue:micBuffer withBufferSize:bufferSize]; 这段代码每次接收音频数据时都会创建一个新的viewController,这很可能不是您想要实现的。 你可能想要做的是在你创建了 ...
-
试图在iOS中调用UITextField的子类的自定义委托方法(Trying to call custom delegate method of subclass of UITextField in iOS)[2024-01-15]
Objective-C将根据属性名称( enumType )而不是类型名称( MyEnumType )自动为您生成setter。 所以你的setter应该是以下代码: [self.mySampleTextField setEnumType:EnumTypeA]; Objective-C will automatically generate setter for you based on the name of the property (enumType) instead of the name of ... -
自定义iOS UITabBarController委托触发器viewDidLoad(Custom iOS UITabBarController Delegate Triggers viewDidLoad)[2022-05-23]
是的, viewdidload每次都会调用,因为您再次初始化选项卡。 setSelectedIndex从UITabbarcontroller类初始化tabbarcontroller evrytime。 你不应该从uitabbarcontroller类那样做。 只是初始化tabbarcontroller onece。 你不应该像这样使用tabbarcontroller 。 根据您的要求,您不需要使用tabbar只需在按钮单击时显示viewController 。 希望这会奏效。 Yes, viewdidloa ... -
您的GoogleLoginWrapper实例超出了viewDidLoad方法末尾的范围,因此会立即取消分配。 您无法使用您发布的代码调用sign...函数。 您应该使用属性而不是局部变量来保持对GoogleLoginWrapper实例的引用。 Your instance of GoogleLoginWrapper goes out of scope at the end of your viewDidLoad method so it is deallocated immediately. You can' ...