Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
when i try to use
foreach (JObject ii in jj.SelectTokens("$[?(@.total_amount > 2)]"))
the list is getting filtered properly for whole numbers. but if the json contains numbers with decimal eg. 25.3 or something i get the exception input string was not in correct format.



sample json:
[[{"doc_code":"123","doc_type":"update inventory","line_number":"1","doc_date":"6/15/2018","Cost Center":"Iconic Solutions","tax_calc_date":"","vendor_id":"Iconic Solutions","use_id":"1","tax_code":"tc105","item_id":"1","description":"desc1","quantity":"1","discount":"","tax_included":"","taxable_amount":"100","charged_tax":"","total_amount":"27.5","Ref1":"","Ref2":"","RevAcct":"","DestAddress":"103 madras","DestCity":"","DestRegion":"","DestPostalCode":"235692","DestCountry":"","OrigAddress":"86nasdnv","OrigCity":"","OrigRegion":"","OrigPostalCode":"23654","OrigCountry":"","DestLocationCode":"","OrigLocationCode":"","PurchaseingAgentCode":"","PurchaseOrderNo":"","address":"","city":"","region":"","postal_code":"","country":"","import_id":"72","company_id":"2","costcenter_id":"","marked_for_allocation":"","is_allocated":"","allocation_method":"","calculated_tax":"","marked_for_review":"","line_item_status":"","warning_status":"","insert_user":"","cutt_line_item_number":"","processing_stage":"","user_id":"21","cut_proc_number":"","variance":"0","purpose_id":"0","error_code_id":"0"}]]


What I have tried:

foreach (JObject lineItem in lineItem1.SelectTokens("$[?(@.total_amount > 1)]"))


is the code i have used and couldnt get it to work with json prop total_amount with 25.6 or any decimal value
Posted
Comments
Afzaal Ahmad Zeeshan 9-Nov-18 5:08am    
What is the type of lineItem1? And how are you parsing the objects?

This seems like a type mismatch, perhaps you are trying to parse a data that does not match the type in the object type.

if the json contains numbers with decimal eg. 25.3 or something i get the exception input string was not in correct format.

However, it works when you have an integer, so just make sure you do not have the object type with an int member.

https://stackoverflow.com/questions/16398352/strange-json-net-exception-input-string-was-not-in-a-correct-format
Richard Deeming 9-Nov-18 7:55am    
Does it work if you include a decimal point in the filter?
lineItem1.SelectTokens("$[?(@.total_amount > 1.0)]")
mithunnivas 13-Nov-18 2:53am    
yes that did the trick. sorry I was not well i couldnt reply.
I tried the above solution just after posting this thread and got it worked. thank you so much for the help.
newtonsoft json net automatically determines the condition based on the type.
mithunnivas 16-Nov-18 3:33am    
hello sir. even now this is not working. when i pass 1.0 or 3.56, it just takes the first digit and compares it. nothing else. still stuck here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900