RakuyoKit / JSONPreview

🎨 A view that previews JSON in highlighted form, it also provides the ability to format and collapse nodes.
MIT License
68 stars 13 forks source link

one more crash:JSONPreview 的 preview(_ json: String, style: HighlightStyle = .default, completion: (() -> Void)? = nil) #10

Closed mxh-mo closed 11 months ago

mxh-mo commented 11 months ago
企业微信截图_4b3718b1-a844-4cca-96be-c7df52633f4e
mxh-mo commented 11 months ago

"{\"tinyId\":\"144115529973900856\",\"originalAccountModel\":{\"accountIdType\":0,\"authKeyType\":0,\"authKey\":\"-xsDf6nk76jKc8Gogrb54g.M\",\"isVisitor\":false,\"accountId\":\"2873916004\"},\"ticketModel\":{\"a2ExpireTime\":1700119148,\"a2Ticket\":\"3216c2ec48d5b894b423601efd24ca8c694a6b1a57550022f658825f0a401e7d5684807871fd19ca8f1626d2c8038b35bf98d0c87febce6aeb91d846112ae4796e949845a2be6d0c\"},\"uid\":\"4999561028\",\"accountStatus\":0}"

mxh-mo commented 11 months ago

@rakuyoMo i provided json string, could you debug this issue first

mxh-mo commented 11 months ago

Use it! Is it too dangerous ?

企业微信截图_ebeb8c54-e3dd-4e09-9e10-e0cf0a023e0f
rakuyoMo commented 11 months ago

@rakuyoMo i provided json string, could you debug this issue first

Okay, I'll troubleshoot this first.

BTW, This isn't the json for #9?

rakuyoMo commented 11 months ago
image

This json displays fine in my demo, have you tried to reproduce your problem using the demo in your project?

The current information is not enough for me to troubleshoot the issue, but I noticed in your screenshot that the self variable has a value of nil, or you should check the method or timing of how you initialize or use the JSONPreview instance. Or provide me more information about it. It would be better if you can directly provide a minimized demo that reproduces the problem.

mxh-mo commented 11 months ago

This is not mandatory

rakuyoMo commented 11 months ago

I have an assumption:

I guess you are using JSONPreview in combination with a list view (UITableView or UICollectiontView).

If this is the case, then it is possible to have a decorator of nil when sliding fast, or in other cases, perhaps in the decorator's didSet method.

decorator is assigned -> Cell of JSONPreview instance‘s superview is released -> decorator is nil in decorator's didSet method.

rakuyoMo commented 11 months ago

@mxh-mo I committed some code on the develop branch, you can try switching to that branch and see if the crash still occurs.

But I'm more concerned about whether the behavior of the JSONPreview object meets your expectations if the crash goes away. I am very concerned about that.

I will close the issue as well as #9 and you can reply under this question if the issue is not resolved.

If the fix causes other issues, you can open a new issue.

Have a nice life.

mxh-mo commented 10 months ago

We fixed code like this:

企业微信截图_eb00394c-6015-485c-a2af-93ce3e7cc941
rakuyoMo commented 10 months ago

The highlight(_: judgmentValid: style:) method will return nil when the json is illegal.

Similar processing has been added to the develop branch. It looks like we can release the change.

mxh-mo commented 10 months ago

but is still crash, then we changed like this:

image

self should be use on main queue, too