在我要附加到字符串变量的网站上有一个段落. 看起来像这样: { "id":"499156235", "login_url":"www.testing/platform/test_account_login.php?user_id=499156235", 电子邮件":"mhuvdfmt_greenesteerin@tfbnw", 密码":"1752836968" } 我想创建两个变量,其中包含电子邮件"和密码"中的值. 因此,使用上面的示例,我将拥有一个带有mhuvdfmt_greenesteerin@tfbnw 的变量 和带有1752836968的变量 解决方案
Try, 字符串 pattern1 = " (?< = \电子邮件\":\ x20 \).*?(?= \")"; 字符串 pattern2 = " (?< = \"密码\:\ x20 \").*?(?= \)" ; 字符串 email = System.Text.RegularExpressions.Regex.Match(input,pattern1).Value; 字符串密码= System.Text.RegularExpressions.Regex.Match(input,pattern2).Value;
男孩好家伙.还没有人注意到这是JSON. 我继续使用以下解决方案: StackOverflow问题 [ ^ ]. 不要使用批准的答案,而应使用页面代码中的16个投票赞成的答案.他用"answer"中的链接库修复了一个错误.
拆分为",然后拆分为:"上的数组的最后两项,以获取用户名和密码.分享您到目前为止尝试过的代码,以便其他人可以提供更好的帮助.
Have a paragraph on a website that I am attaching to a string variable. Looks something like this: { "id": "499156235", "login_url": "www.testing/platform/test_account_login.php?user_id=499156235", "email": "mhuvdfmt_greenesteerin@tfbnw", "password": "1752836968" } I want to create two variables that contain the values from Email and Password. So using the above example i would have a variable with mhuvdfmt_greenesteerin@tfbnw and a variable with 1752836968 Tried using Regex and split but can''t seem to get it to work.
解决方案 Try, string pattern1 = "(?<=\"email\":\x20\").*?(?=\")"; string pattern2 = "(?<=\"password\":\x20\").*?(?=\")"; string email = System.Text.RegularExpressions.Regex.Match(input, pattern1).Value; string password = System.Text.RegularExpressions.Regex.Match(input, pattern2).Value;Boy oh boy. No one has noticed that this is JSON yet. I continue to use the solution from the: StackOverflow Question[^]. Don''t use the approved answer, but instead use the 16 Up-voted answer with the code in the page. He fixed a bug with the linked library in the "answer".Split over "," then split last two items in the array over ":" to get the username and password. Share the code you have tried so far so that someone can provide better help.更多推荐
字符串中的字符串
发布评论