Easiest way to parse “querystring” formatted data

后端 未结 6 1862
误落风尘
误落风尘 2020-11-29 09:11

With the following code:

string q = \"userID=16555&gameID=60&score=4542.122&time=343114\";

What would be the easiest way to par

6条回答
  •  鱼传尺愫
    2020-11-29 09:30

    Pretty easy... Use the HttpUtility.ParseQueryString method.

    Untested, but this should work:

    var qs = "userID=16555&gameID=60&score=4542.122&time=343114";
    var parsed = HttpUtility.ParseQueryString(qs);
    var userId = parsed["userID"]; 
    //  ^^^^^^ Should be "16555".  Note this will be a string of course.
    

提交回复
热议问题